Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Hostname -> IP Address

Reply
 
Old 09-11-2008   #1 (permalink)
Todd Walton


 
 

Hostname -> IP Address

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?

-todd

My System SpecsSystem Spec
Old 09-11-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Hostname -> IP Address


"Todd Walton" <tdwalton@xxxxxx> wrote in message
news:ed68aae7-0520-4ced-b746-4e7e0374d0bc@xxxxxx
Quote:

> 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?
>
> -todd
You could use this one-line batch file:
@echo off
for /F "tokens=3 delims=: " %%a in ('ping HostName ^| find /i "bytes="') do
set IP=%%a


My System SpecsSystem Spec
Old 09-11-2008   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Hostname -> IP Address

Todd Walton wrote:
Quote:

> 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.
>
I have four VBScript example functions linked on this page that retrieve the
IP address of the local computer:

http://www.rlmueller.net/PingComputers.htm

The page explains what is required for each function.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 09-11-2008   #4 (permalink)
James Whitlow


 
 

Re: Hostname -> IP Address

"Todd Walton" <tdwalton@xxxxxx> wrote in message
news:ed68aae7-0520-4ced-b746-4e7e0374d0bc@xxxxxx
Quote:

> 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


My System SpecsSystem Spec
Old 09-12-2008   #5 (permalink)
Todd Walton


 
 

Re: Hostname -> IP Address

On Sep 11, 4:07*pm, "James Whitlow" <jwhitlow.60372...@xxxxxx>
wrote:
Quote:

> * * 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
Beautiful! Simple! I like it.

Thank you James.

-todd
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Net use with hostname fails, IP address works fine Vista networking & sharing
Extract hostname from distinguished name PowerShell
Hostname to IP translation PowerShell
Invalid Hostname Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46