Ipaddress in a file need the machine names

bsharath
bsharath used Ask the Experts™
on
Hi All,

Ipaddress in a file need the machine names

I need help with a vbs or Batch script that can get the machine names of all ip's in a file. if not live can get from the DNS/DHCP server

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
You might want to take a look at this tool:

http://www.nirsoft.net/utils/fastresolver.html

~bp
IT / Software Engineering Consultant
Top Expert 2016
Commented:
ipconfig /all is the command to get all the details including hostname.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Most Valuable Expert 2012
Top Expert 2014
Commented:
And you can try this VBS.

Rob.
dim strInputPath, strOutputPath, strStatus
dim objFSO, objTextIn, objTextOut

strInputPath  = "d:\input.dat"
strOutputPath = "d:\output.dat"

Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
set objTextIn  = objFSO.OpenTextFile(strInputPath,1)
set objTextout = objFSO.CreateTextFile(strOutputPath,1)

objTextOut.WriteLine("Computer  Ip address")

While Not objTextIn.AtEndOfStream
	strcomputer = Trim(objTextIn.Readline)
	If strComputer <> "" Then
		strResult = ResolveIP(strComputer)
		If strResult <> "IP Address could not be resolved" Then
			objTextOut.writeline strcomputer & "   " & strResult
		Else
			objTextOut.writeline strcomputer & "   " & "Ping Failed"
		End If
	End If
Wend
objtextin.close
objtextout.close
wscript.echo "Job Done"

Function ResolveIP(computerName)
	Set objShell = CreateObject("WScript.Shell")
	strTempFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "TempPing.txt"
	objShell.Run "cmd /c ping -n 1 -w 1000 " & computerName & " > """ & strTempFile & """", 0, True
	Set objFile = objFSO.OpenTextFile(strTempFile, 1, False)
	strOutput = LCase(objFile.ReadAll)
	objFile.Close
	objFSO.DeleteFile strTempFile, True
	Set RegEx = New RegExp
	RegEx.Pattern = "\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]"
	RegEx.Global = True
	If RegEx.Test(strOutput) Then
		ResolveIP = RegEx.Execute(strOutput)(0).Submatches(0)
	Else
		ResolveIP = "IP Address could not be resolved"
	End If
End Function

Open in new window

Author

Commented:
Rob i get this


---------------------------
Windows Script Host
---------------------------
Script:      D:\All\Find machine names.vbs
Line:      33
Char:      2
Error:      File not found
Code:      800A0035
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
Most Valuable Expert 2012
Top Expert 2014

Commented:
That means the ping didn't execute....have you removed empty lines from your input file?

Author

Commented:
Rob,

There are no empty lines all ipaddresses only
Most Valuable Expert 2012
Top Expert 2014

Commented:
I guess you may not have the rights to write the temp file to the same folder where the script is.  If you're on Windows Vista or 7, does it make any difference if you run a command prompt "As Administrator" and then type
cscript "D:\All\Find Machine Names.vbs"

Rob.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial