Clicky

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

asked 12/13/2011 11:48

bsharath's gravatar image

bsharath ♦♦


9 Answers:
You might want to take a look at this tool:

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

~bp
link

answered

billprew's gravatar image

billprew

link

answered 2011-12-13 at 19:54:03

billprew's gravatar image

billprew

ipconfig /all is the command to get all the details including hostname.
link

answered 2011-12-13 at 19:56:37

wasimibm's gravatar image

wasimibm

And you can try this VBS.

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
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
link

answered 2011-12-13 at 20:09:14

RobSampson's gravatar image

RobSampson

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  
---------------------------
link

answered 2011-12-13 at 20:50:58

bsharath's gravatar image

bsharath

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

answered 2011-12-13 at 21:02:24

RobSampson's gravatar image

RobSampson

Rob,

There are no empty lines all ipaddresses only
link

answered 2011-12-13 at 21:25:16

bsharath's gravatar image

bsharath

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.
link

answered 2011-12-13 at 21:37:54

RobSampson's gravatar image

RobSampson

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×3
×23
×9

Asked: 12/13/2011 11:48

Seen: 180 times

Last updated: 12/15/2011 01:54