B4J Question Ping server

Discussion in 'B4J Questions' started by bogdanc, Feb 7, 2017.

  1. bogdanc

    bogdanc Active Member Licensed User

    Hi All!

    While a go I asked how to ping server and get respond.
    I've got some answer but it only tells me that server is responding.
    How to get similar thing as it on win shell cmd with the number of packets received or lost and time of respond?

    Code:
    Sub Ping(ipaddress As String)
        
    Log("started")
        
    Dim shl As Shell
        
    Dim lstParams As List: lstParams.Initialize
        
    Try
            
    Dim os As String = GetSystemProperty("os.name""").ToLowerCase
            
    If os.Contains("win"Then
                
    Log("Windows")
                
    'Windows
                lstParams.Add("-n")
            
    Else
                
    'Linux and Mac
                lstParams.Add("-c")
            
    End If
            lstParams.Add(
    "1")
            lstParams.Add(ipaddress)
            
            shl.Initialize(
    "shl""ping", lstParams)
            shl.WorkingDirectory = 
    File.DirApp
            shl.Run(-
    1)
        
    Catch
            
    Log(LastException.Message)
        
    End Try
    End Sub
    Thank you for any help in advance.
     
  2. udg

    udg Expert Licensed User

    Are you looking for the "feedback" from a successful ping command?
    Did you add something like the following to your code?
    Code:
    Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut AsString, StdErr AsString)
    If Success AND ExitCode = 0 Then 
       
    Log("Success")
       
    Log(StdOut)
    Else
       
    Log("Error: " & StdErr)
    EndIf
    ExitApplication
    End Sub
    Are you aware that many installations don't allow reply to a ping command?

    udg
     
  3. bogdanc

    bogdanc Active Member Licensed User

    Thank You for You replay!

    Yes. I need to have a feedback from shell.

    No i'm getting some output.


    Code:
    .....
    Packets: Sent = 
    1, Received = 1, Lost = 0 (0% loss),   
    Minimum = 3ms, Maximum = 3ms, Average = 3ms
    .....
    1)
    is it a way to strip the info the get time and packet's losts?

    put this to the variable and search for: Average = and cut it to display rest of string.

    2) Second how to ping 4 ips on the same time?

    Code:
    lstParams.Add(ipaddress1)
    lstParams.Add(ipaddress2)
    .
    .
    .
    lstParams.Add(ipaddressN)
     
  4. udg

    udg Expert Licensed User

    Hi,

    have a look at RegEx for a powerful method to extract info from a non-structured text (i.e. your StdOut as retuned by jshell after executing the ping command).
    AFAIK, ping command works on a single address at time. You could list a few addresses in a global list, process on item at time (the top one), remove it an so on while you ha ve items in the list.
     
  5. inakigarm

    inakigarm Well-Known Member Licensed User

    udg likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice