Ipaddress in a file need the machine names

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

LVL 11
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
You might want to take a look at this tool:


Bill PrewIT / Software Engineering ConsultantCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wasim Akram ShaikCommented:
ipconfig /all is the command to get all the details including hostname.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

And you can try this VBS.

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
			objTextOut.writeline strcomputer & "   " & "Ping Failed"
		End If
	End If
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)
	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)
		ResolveIP = "IP Address could not be resolved"
	End If
End Function

Open in new window

bsharathAuthor 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

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

There are no empty lines all ipaddresses only
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"

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.