Solved

Resolve Server Name to IP

Posted on 2008-10-28
4
2,127 Views
Last Modified: 2012-05-05
Is there a script that resolve a server name to IP address?
0
Comment
Question by:dongocdung
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:aschaef217
aschaef217 earned 450 total points
ID: 22821885
Give this page a look.  It has a bat script called resolve.bat that will resolve the IP, DNS name, and Netbios name.  I'm sure you can remove the other 2 parts that resolve DNS and Netbios if you don't need them.
http://windowsitpro.com/article/articleid/81635/jsi-tip-8389-resolve-script-returns-the-ip-address-dns-name-and-netbios-name-of-a-computer.html
 
0
 

Author Comment

by:dongocdung
ID: 22822116
Can I get VB scripting instead of bat file?
0
 
LVL 22

Assisted Solution

by:danaseaman
danaseaman earned 50 total points
ID: 22822142
Vb6 code to resolve IP from URL:
URL to IP ... http://vbnet.mvps.org/code/network/iplookup.htm

Note: In demo Rem line "Text1.Text = GetMachineName()" so you can enter URL in Text1.
0
 
LVL 6

Accepted Solution

by:
aschaef217 earned 450 total points
ID: 22822284
Here is another script to do it in VB.
'****************************************************************

'  File:    getipname.vbs  (WSH for VBscript)

'  Author:           M. Gallant    09/30/2001

'

'  Based on script by M. Harris & T. Lavedas:

'  posted to: microsoft.public.scripting.vbscript  2000/07/21  
 

'  Reads IP addresses via:

'    ipconfig.exe  (NT4 and Win2000)

'    winipcfg.exe  (Win95)

'  For NT4, Win2000 resolves IP addresses to FQDN names via:

'     nslookup.exe     (with default DNS server)

' 

'****************************************************************

'Modified 2/2/02 to just show the IP addresses - Doug Knox

'Original script located at:  http://home.istar.ca/~neutron/wsh/IPInfo/getipname.html

arAddresses = GetIPAddresses()
 

info = ""
 

for each ip in arAddresses

    info = info & ip & vbTab & GetFQDN(ip) & vbCR

next
 

  WScript.echo info
 

Function GetFQDN(ipaddress)

'====

' Returns Fully Qualified Domain Name

' from reverse DNS lookup via nslookup.exe

' only implemented for NT4, 2000

'====

  set sh = createobject("wscript.shell")

  set fso = createobject("scripting.filesystemobject")

  Set Env = sh.Environment("PROCESS")
 

  if Env("OS") = "Windows_NT" then

    workfile = fso.gettempname

    sh.run "%comspec% /c nslookup " & ipaddress & "  > " & workfile,0,true

   set sh = nothing

   set ts = fso.opentextfile(workfile)

   data = split(ts.readall,vbcr)

   ts.close

   set ts = nothing

   fso.deletefile workfile

   set fso = nothing

  for n = 0 to ubound(data)

    if instr(data(n),"Name") then

      parts = split(data(n),":")

        hostname= trim(cstr(parts(1)))

       Exit For

    end if

    hostname = "could not resolve IP address"

  next

    GetFQDN = hostname

  else

   set sh = nothing

   set fso = nothing

   GetFQDN = ""

  end if

End Function
 
 

Function GetIPAddresses()

'=====

' Returns array of IP Addresses as output

' by ipconfig or winipcfg...

'

' Win98/WinNT have ipconfig (Win95 doesn't)

' Win98/Win95 have winipcfg (WinNt doesn't)

'

' Note: The PPP Adapter (Dial Up Adapter) is

' excluded if not connected (IP address will be 0.0.0.0)

' and included if it is connected.

'=====

  set sh = createobject("wscript.shell")

  set fso = createobject("scripting.filesystemobject")
 

  Set Env = sh.Environment("PROCESS")

  if Env("OS") = "Windows_NT" then

    workfile = fso.gettempname

    sh.run "%comspec% /c ipconfig > " & workfile,0,true

  else

    'winipcfg in batch mode sends output to

    'filename winipcfg.out

    workfile = "winipcfg.out"

    sh.run "winipcfg /batch" ,0,true

  end if

  set sh = nothing

  set ts = fso.opentextfile(workfile)

  data = split(ts.readall,vbcr)

  ts.close

  set ts = nothing

  fso.deletefile workfile

  set fso = nothing

  arIPAddress = array()

  index = -1

  for n = 0 to ubound(data)

    if instr(data(n),"IP Address") then

      parts = split(data(n),":")

      if trim(parts(1)) <> "0.0.0.0" then

        index = index + 1

        ReDim Preserve arIPAddress(index)

        arIPAddress(index)= trim(cstr(parts(1)))

      end if

    end if

  next

  GetIPAddresses = arIPAddress

End Function

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now