Link to home
Create AccountLog in
Avatar of bsharath
bsharathFlag for India

asked on

Convert the list of Ip's to machine names.

Hi,

I have a list of ip's in a txt file.IS there a way to convert all of them to Machinenames next to the ip address.

Regards
Sharath
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of ghostdog74
ghostdog74

here's a vbscript:


Set objFSO=CreateObject("Scripting.FileSystemObject")
myIPs = "c:\temp\ips.txt" 'your ip list
Set objFile = objFSO.OpenTextFile(myIPs,1)
Do Until objFile.AtEndOfLine
      strComputer = objFile.ReadLine
      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
      For Each objAdapter in colAdapters
         If Not IsNull(objAdapter.IPAddress) Then
            For i = 0 To UBound(objAdapter.IPAddress)
               WScript.Echo objAdapter.IPAddress(i) & ":" & objAdapter.DNSHostName
            Next
         End If
      Next
Loop

usage: c:\> cscript /nologo  myscript.vbs > newfile
Avatar of bsharath

ASKER

Farhan Sorry for the delay.

Your code is working fine.

ghostdog74
I get this.

C:\>cscript /nologo  "ip's to machine names.vbs" > newfile
C:\ip's to machine names.vbs(6, 7) Microsoft VBScript runtime error: The remote
server machine does not exist or is unavailable: 'GetObject'

I think we need more error checking...
On error resume Next
Set objFSO=CreateObject("Scripting.FileSystemObject")
myIPs = "c:\temp\ips.txt" 'your ip list
Set objFile = objFSO.OpenTextFile(myIPs,1)
Do Until objFile.AtEndOfLine
      strComputer = objFile.ReadLine
      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
      For Each objAdapter in colAdapters
         If Not IsNull(objAdapter.IPAddress) Then
            For i = 0 To UBound(objAdapter.IPAddress)
               WScript.Echo objAdapter.IPAddress(i) & ":" & objAdapter.DNSHostName
            Next
         End If
      Next
Loop