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

Thanks
LVL 11
bsharathAsked:
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 PrewCommented:
You might want to take a look at this tool:

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

~bp
0
Bill PrewCommented:
0

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.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

RobSampsonCommented:
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

0
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

---------------------------
OK  
---------------------------
0
RobSampsonCommented:
That means the ping didn't execute....have you removed empty lines from your input file?
0
bsharathAuthor Commented:
Rob,

There are no empty lines all ipaddresses only
0
RobSampsonCommented:
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.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.