How to ping a site

lock255

Well-Known Member
Licensed User
Longtime User
Hi I am creating a program that does ping a website, so what I need is:
1) Know whether the site is online
2) the IP address of the server
If someone helps me I'd be really grateful. I just started programming with B4A, so I ask you spieghermi things in a simple and step by step.
 

fanfalveto

Active Member
Licensed User
Longtime User
i do ping with this
B4X:
dim p as Phone
Dim sb As StringBuilder
p.Shell("ping -c 1 192.168.1.1",Null,sb,Null)
Log(sb)
 
Upvote 0

lock255

Well-Known Member
Licensed User
Longtime User
i do ping with this
B4X:
dim p as Phone
Dim sb As StringBuilder
p.Shell("ping -c 1 192.168.1.1",Null,sb,Null)
Log(sb)


fanfalveto, can you explain what the code does?
B4X:
p.Shell("ping -c 1 192.168.1.1",Null,sb,Null)
 
Upvote 0

lock255

Well-Known Member
Licensed User
Longtime User
i think p.shell(ping .........) call to /system/bin/ping

I want to enter in a textbox, the link of the websites that want to have their ping to test if they are with up / down and the number of the server. Please you can learn by example, adapting it to what I need?
Thanks for your time.
 
Upvote 0

lock255

Well-Known Member
Licensed User
Longtime User
try this
B4X:
dirIP = textbox1.Text
p.Shell("ping -c1 " & dirIP, Null, sb, Null)

Wrong, the program pauses .. If I have to assign permissions in Minefest?

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim p As Phone
   Dim sb As StringBuilder
   Dim dirIP As String
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   Activity.LoadLayout("ping_layout") 'Collega il layout del Designer al programma
dirIP = EditText1.text
p.Shell("ping -c1 " & dirIP, Null, sb, Null)
End Sub
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I don't know what to say. I have included sb.initialize of course, but the ping works only when I'm in debug. In release the program do nothing.
Here the full code

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
    Dim p As Phone
    Dim sb As StringBuilder
    Dim dirIP As String
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim Label1 As Label
   Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")

   
      Activity.LoadLayout("main") 'Collega il layout del Designer al programma
   sb.Initialize
   
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Button1_Click
   
   Log("ping")
   
   dirIP = "www.google.com"
   p.Shell("ping -c1 " & dirIP, Null, sb, Null)
   Log(sb)
   Label1.Text=sb
   
End Sub

Marco
 
Upvote 0
Top