"Todd Walton" <tdwalton@xxxxxx> wrote in message
news:ed68aae7-0520-4ced-b746-4e7e0374d0bc@xxxxxx
> Any ideas on how best to get the IP address of a hostname, using
> VBScript? Right now I'm exec'ing a ping command, which gives output
> like this:
>
> ===============================================
>
> H:\>ping cmp092
>
> Pinging cmp092.example.com [167.190.237.59] with 32 bytes of data:
>
> Reply from 167.190.237.59: bytes=32 time=1ms TTL=128
> Reply from 167.190.237.59: bytes=32 time<1ms TTL=128
> Reply from 167.190.237.59: bytes=32 time<1ms TTL=128
> Reply from 167.190.237.59: bytes=32 time<1ms TTL=128
>
> Ping statistics for 167.190.237.59:
> Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
> Approximate round trip times in milli-seconds:
> Minimum = 0ms, Maximum = 1ms, Average = 0ms
>
> ===============================================
>
> I iterate through line for line, find the one that starts with
> "Pinging" and then use a regex to pull out the IP address into a
> collection.
>
> Any better ideas? You can use 'Win32_PingStatus Class' if you are using Windows XP or
above. This is the link to the Microsoft page:
http://msdn.microsoft.com/en-us/libr...50(VS.85).aspx
Below is a small sample:
sHost = "MYCOMPUTER"
For Each oIP in GetObject("winmgmts:").ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE address = '" & sHost & "'")
sIP = oIP.ProtocolAddress
Next
MsgBox sIP, , sHost