Ping excel script and get ip reply

mowael

New Member
Joined
Aug 17, 2023
Messages
1
Office Version
  1. 2019
Hello,

I have a Hostname List and I need a result = ip (172,217,19,132)
1692327723683.png


I tried to search on it but everyone is talking about time response, so I need to know how to search on a document.
1692327796026.png


Part of a script down there is getting ( result + Response time + TTL )_ im sure these belong to the liberary that added in the script beginning "objping"
I tried to search on the package, but I got no results, my thoughts are that there's other results it can get, so if i read what this package can get I can get all results I need ? so how

1692327953180.png
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Here is some code that will give you the ping results.
I hope this helps you.

VBA Code:
Sub Test_Connection()
  i = 1
  'While (ActiveSheet.Cells(i, 1) <> "")
    'Retrieve IP address
    strCompAddress = ActiveSheet.Cells(i, 1)  'IP Address in Cell A1
    
    '//Setup Shell command for Ping
    '//NOTE: Make to leave a space after PING.exe
    Dim strShellCommand As String
    strShellCommand = "C:\Windows\System32\PING.exe -a " + strCompAddress
    
    '//Create Shell Object in to run Scripts
    Set oSh = CreateObject("WScript.Shell")
    Set oEx = oSh.Exec(strShellCommand)
    
    '//Read output buffer
    strbuf = oEx.StdOut.ReadAll
    ActiveSheet.Cells(i, 9) = strbuf
    ActiveSheet.Cells(i, 8) = Split(strbuf, ",")(2)
    ActiveSheet.Cells(i, 7) = Split(strbuf, " ")(1)
  'Wend
End Sub

This code does some parsing of the Ping Results
VBA Code:
Sub SplitPingResult()
  Dim tmp, x, vals
  Dim icolon, iequal
  tmp = Split(Range("B1"), vbLf)
  For x = 0 To UBound(tmp)
    Cells(x + 2, 1) = tmp(x)
    
    icolon = InStr(tmp(x), ": ")
    If icolon > 0 Then
      Cells(x + 2, 2) = Left(tmp(x), icolon - 1) 'Reply from x.x.x.x
      Cells(x + 2, 3) = Mid(tmp(x), icolon + 2) 'bytes, time, TTL
      vals = Split(Cells(x + 2, 3), ", ")
      If UBound(vals) = 0 Then vals = Split(Cells(x + 2, 3), " ")
      If UBound(vals) > 0 Then
        Cells(x + 2, 4) = vals(0)
        Cells(x + 2, 5) = vals(1)
        Cells(x + 2, 6) = vals(1)
      End If
    End If
  Next x
End Sub

Sample of partially parsed Ping Results data

Book3
ABCDEF
110.0.1.1 Pinging S4HSOTANO [10.0.1.1] with 32 bytes of data: Reply from 10.0.1.1: bytes=32 time=1ms TTL=255 Reply from 10.0.1.1: bytes=32 time=1ms TTL=255 Reply from 10.0.1.1: bytes=32 time<1ms TTL=255 Reply from 10.0.1.1: bytes=32 time=1ms TTL=255 Ping statistics for 10.0.1.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 1ms, Average = 0ms BytesTimeTTL
2 Pinging S4HSOTANO [10.0.1.1] with 32 bytes of data:
3Reply from 10.0.1.1: bytes=32 time=1ms TTL=255 Reply from 10.0.1.1bytes=32 time=1ms TTL=255 bytes=32time=1mstime=1ms
4Reply from 10.0.1.1: bytes=32 time=1ms TTL=255 Reply from 10.0.1.1bytes=32 time=1ms TTL=255 bytes=32time=1mstime=1ms
5Reply from 10.0.1.1: bytes=32 time<1ms TTL=255 Reply from 10.0.1.1bytes=32 time<1ms TTL=255 bytes=32time<1mstime<1ms
6Reply from 10.0.1.1: bytes=32 time=1ms TTL=255 Reply from 10.0.1.1bytes=32 time=1ms TTL=255 bytes=32time=1mstime=1ms
7
8Ping statistics for 10.0.1.1:
9 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), PacketsSent = 4, Received = 4, Lost = 0 (0% loss), Sent = 4Received = 4Received = 4
10Approximate round trip times in milli-seconds:
11 Minimum = 0ms, Maximum = 1ms, Average = 0ms
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,410
Messages
6,124,755
Members
449,187
Latest member
hermansoa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top