Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Convert the list of Ip's to machine names.

Posted on 2007-09-29
4
Medium Priority
?
471 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:bsharath
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Farhan Kazi earned 2000 total points
ID: 19983425
:: ================
:: READ THIS FIRST
:: ================
:: * This script require "Computers.txt" file from where it will pick IP addresses.
:: * Copy and Paste following script into notepad and save it with any name having .cmd extension.
:: SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion
IF NOT EXIST Computers.txt Goto ShowErr
FOR %%R IN (Computers.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST IP2NameRpt.txt DEL /F /Q IP2NameRpt.txt
FOR /F %%c IN ('Type Computers.txt') Do (
    Echo Processing: %%c
      PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
      IF NOT ErrorLevel 1 (
            FOR /F "Tokens=2" %%i IN ('PING -a -n 1 -w 1000 %%c ^|Find "["') DO ECHO %%c: %%i >>IP2NameRpt.txt
      )ELSE (Echo %%c: Unable to connect)
)      
Goto EndScript
:ShowErr
Echo "Computers.txt" file does not exist or file is empty!
:EndScript
ENDLOCAL
EXIT /B 0
:: SCRIPT END
0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 19986047
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
0
 
LVL 11

Author Comment

by:bsharath
ID: 19986445
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...
0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 19987046
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
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

580 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