Get IP address from domain name using vbscript?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Get IP address from domain name using vbscript?

Post by Me_again » Wed Sep 08, 2010 3:16 pm

Can the vbscript code in this tip be modified to also return the IP address it is pinging?

http://www.mjtnet.com/forum/viewtopic.p ... light=ping

(I know I can do this with command line ping > file but I don't want to go that route.)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Sep 08, 2010 3:34 pm

Use the ProtocolAddress property:

Code: Select all

VBSTART
Function Ping(strHost)
  dim objPing, objRetStatus

  ipAddress = ""
  set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery ("select * from Win32_PingStatus where address = '" & strHost & "'")

  for each objRetStatus in objPing
    if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
      Ping = ""
    else
      Ping = objRetStatus.ProtocolAddress
    end if
  next
End Function
VBEND

VBEval>Ping("google.com"),pinged
If>pinged<>{""}
  MessageModal>Ip Address is: %pinged%
Else
  MessageModal>host not contacted
Endif
See:
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Sep 08, 2010 3:40 pm

Thanks Marcus :D You're too fast, I had just found ProtocolAddress but couldn't figure out how to get it into a variable.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts