bsharath
asked on
Ping machines in a txt file and save results in 2 ways.
Hi,
Ping machines in a txt file and save results in 2 ways.
I will have machine names in the txt file
Need to ping and get the ip address and then ping ip with -a and get the machine name
reason is many machines show wrong machine names when pinged so need this report.
Any help is great use
regards
raja
Ping machines in a txt file and save results in 2 ways.
I will have machine names in the txt file
Need to ping and get the ip address and then ping ip with -a and get the machine name
reason is many machines show wrong machine names when pinged so need this report.
Any help is great use
regards
raja
Have you checked your DNS for any issues first.
This sounds like an DNS issue to me.
He is was script you can use to collect the info you are talking about. It will need to be modified according to your ip range.
This sounds like an DNS issue to me.
He is was script you can use to collect the info you are talking about. It will need to be modified according to your ip range.
on error resume next
dim i
For i = 1 to 254
PingHost
Wscript.echo "192.168.0." & i & vbtab & Pinghost
Next
Function PingHost
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping 192.168.0." & i & " -a")
strPingResults = LCase(objExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
PingHost = True
Else
PingHost = False
End If
end Function
ASKER
But these will not take each and ping with name and ip address to find the ones that has issues
are you using AD?
If so I an a script that will need to be modified for your domain, but it collects details that you are looking for.
If so I an a script that will need to be modified for your domain, but it collects details that you are looking for.
ASKER
Yes its AD.
I have a script at work that I will post when I get in within the next hour.
Here is my code that will return ip to Computer name.
If may take some time to run through depending on the number of computers.
I set i = a very small range for testing.
If you want it to output to a test file (Tab delimated) run it from the command prompt
cscript "vbs file name.vbs " > .\outputfile.csv
If may take some time to run through depending on the number of computers.
I set i = a very small range for testing.
If you want it to output to a test file (Tab delimated) run it from the command prompt
cscript "vbs file name.vbs " > .\outputfile.csv
on error resume next
Dim StrComputerName, StrUser, strManufacturer, StrModel, StrSN
'***************************
'Change your range here
'***************************
For i = 199 to 200
'***************************
'Change your subnet here
'***************************
strname = "192.168.11." & i
blnPing = PingHost
If blnPing = True Then
end if
DataCollection
next
'************************************************************************************
'Data Collection *
'************************************************************************************
Function DataCollection
set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strName & "\root\cimv2")
Set colSystems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objSystem In colSystems
strComputerName = objSystem.name
next
wscript.echo Strname & vbtab & StrCOmputerName
End Function
'************************************************************************************
'Ping Computer *
'************************************************************************************
Function PingHost
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strName)
strPingResults = LCase(objExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
PingHost = True
Else
PingHost = False
End If
End Function
'************************************************************************
let me know how it goes and if you have any questions.
I would like to post an edit to the code:
Original
Original
blnPing = PingHost
If blnPing = True Then
end if
DataCollection
Edit blnPing = PingHost
If blnPing = True Then
DataCollection
end if
ASKER
No errors and no outputs
I will check when I get in.
8:00 am EST
8:00 am EST
Can you post your code?
I just tested this against my network and it worked.
Can try running it without the Output parameter and see if you get results.
Can you post your version of the code?
Can try running it without the Output parameter and see if you get results.
Can you post your version of the code?
ASKER
Sorry but does not show both
I will have machine names. It has to ping machine name and get the ip and then ping the retrieved ip and then get machine name.
I will have machine names. It has to ping machine name and get the ip and then ping the retrieved ip and then get machine name.
See how this code goes.
Regards,
Rob.
Regards,
Rob.
strComputers = "computers.txt"
strOutput = "results.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strComputers, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """Computer"",""Resolved IP"",""Resolved Host Name"""
While Not objInput.AtEndOfStream
strComputer = objInput.ReadLine
If Trim(strComputer) <> "" Then
strIP = ResolveIPNSLookup(strComputer)
strHostName = ResolveHostName(strIP)
objOutput.WriteLine """" & strComputer & """,""" & strIP & """,""" & strHostName & """"
End If
Wend
objOutput.Close
objInput.Close
MsgBox "Done."
Function ResolveIPNSLookup(computerName)
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("nslookup " & computerName)
strPingOutput = objExec.StdOut.ReadAll
Set RegEx = New RegExp
RegEx.Pattern = "(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
RegEx.Global = True
If RegEx.Test(strPingOutput) Then
If RegEx.Execute(strPingOutput).Count > 1 Then
ResolveIPNSLookup = RegEx.Execute(strPingOutput)(1)
Else
ResolveIPNSLookup = "IP Address could not be resolved"
End If
Else
ResolveIPNSLookup = "IP Address could not be resolved"
End If
End Function
Function ResolveHostName(strIPAddress)
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("nbtstat -a " & strIPAddress)
strHNOutput = objExec.StdOut.ReadAll
Set RegEx = New RegExp
RegEx.Pattern = ".*<00>.*UNIQUE.*"
RegEx.Global = True
If RegEx.Test(strHNOutput) Then
strText = Trim(RegEx.Execute(strHNOutput)(0))
ResolveHostName = Left(strText, InStr(strText, " ") - 1)
Else
ResolveHostName = "Hostname could not be resolved"
End If
End Function
ASKER
Thanks Rob
In colum C i get this
Machine name <00>
At the end get <00>
is there any meaning for this
In colum C i get this
Machine name <00>
At the end get <00>
is there any meaning for this
It's part of the nbtstat output. Try this to get rid of that.
Regards,
Rob.
Regards,
Rob.
strComputers = "computers.txt"
strOutput = "results.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strComputers, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """Computer"",""Resolved IP"",""Resolved Host Name"""
While Not objInput.AtEndOfStream
strComputer = objInput.ReadLine
If Trim(strComputer) <> "" Then
strIP = ResolveIPNSLookup(strComputer)
strHostName = ResolveHostName(strIP)
objOutput.WriteLine """" & strComputer & """,""" & strIP & """,""" & strHostName & """"
End If
Wend
objOutput.Close
objInput.Close
MsgBox "Done."
Function ResolveIPNSLookup(computerName)
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("nslookup " & computerName)
strPingOutput = objExec.StdOut.ReadAll
Set RegEx = New RegExp
RegEx.Pattern = "(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
RegEx.Global = True
If RegEx.Test(strPingOutput) Then
If RegEx.Execute(strPingOutput).Count > 1 Then
ResolveIPNSLookup = RegEx.Execute(strPingOutput)(1)
Else
ResolveIPNSLookup = "IP Address could not be resolved"
End If
Else
ResolveIPNSLookup = "IP Address could not be resolved"
End If
End Function
Function ResolveHostName(strIPAddress)
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("nbtstat -a " & strIPAddress)
strHNOutput = objExec.StdOut.ReadAll
Set RegEx = New RegExp
RegEx.Pattern = ".*<00>.*UNIQUE.*"
RegEx.Global = True
If RegEx.Test(strHNOutput) Then
strText = Trim(RegEx.Execute(strHNOutput)(0))
strText = Left(strText, InStr(strText, " ") - 1)
If InStr(strText, "<") > 0 Then strText = Left(strText, InStr(strText, "<") - 1)
ResolveHostName = strText
Else
ResolveHostName = "Hostname could not be resolved"
End If
End Function
ASKER
Rob
another issue
I get this for many
But when i ping manually it shows the ip address
IP Address could not be resolved Hostname could not be resolved
another issue
I get this for many
But when i ping manually it shows the ip address
IP Address could not be resolved Hostname could not be resolved
The IP Address uses nslookup
For one of those, if you manually do
nslookup YourComputerName
the last IP address in the output should be the IP address.
Rob.
For one of those, if you manually do
nslookup YourComputerName
the last IP address in the output should be the IP address.
Rob.
ASKER
I get this
C:\>nslookup M-XP043
Server: inad.dev.co.uk
Address: 129.110.110.125
DNS request timed out.
timeout was 2 seconds.
*** Request to inad.co.uk timed-out
But when i ping i get the ip and the machine is live
C:\>nslookup M-XP043
Server: inad.dev.co.uk
Address: 129.110.110.125
DNS request timed out.
timeout was 2 seconds.
*** Request to inad.co.uk timed-out
But when i ping i get the ip and the machine is live
I am confused
What went wrong with my script?
Your issue really sounds that it is a DNS issue.
Have you confirmed that replication is working properly?
Is salvaging setup on DNS?
One other thing. Your ip-address looks like it's a public class and not 10. , 172. Or 192.168.
All your computers are public?
What went wrong with my script?
Your issue really sounds that it is a DNS issue.
Have you confirmed that replication is working properly?
Is salvaging setup on DNS?
One other thing. Your ip-address looks like it's a public class and not 10. , 172. Or 192.168.
All your computers are public?
ASKER
Yes all computers are public
Yes we do have dns issue but in other hand want to find systems that have the issue
Yes we do have dns issue but in other hand want to find systems that have the issue
How many computers are you dealing with in total?
How many are ones in question so far?
How many dns servers?
Do you know if salvaging is enabled on the DNS servers?
Have you run any diags on the dns replication?
How many are ones in question so far?
How many dns servers?
Do you know if salvaging is enabled on the DNS servers?
Have you run any diags on the dns replication?
ASKER
How many computers are you dealing with in total?
2000
How many are ones in question so far?
How many dns servers?
2
Do you know if salvaging is enabled on the DNS servers?
Its enabled
Have you run any diags on the dns replication?
No
2000
How many are ones in question so far?
How many dns servers?
2
Do you know if salvaging is enabled on the DNS servers?
Its enabled
Have you run any diags on the dns replication?
No
So what I would do next is compare the 2 dns servers records. They should match if all 2000 machines should be talking to both servers for resolution.
Then I would make sure that these two servers can stay in sync. If your servers are not replicating to each other this could be your root cause.
Are your dhcp managed by you or hosted?
If you have access to the dhcp servers you can also compare the records with your dns records.
Then I would make sure that these two servers can stay in sync. If your servers are not replicating to each other this could be your root cause.
Are your dhcp managed by you or hosted?
If you have access to the dhcp servers you can also compare the records with your dns records.
Also if possible can you give a discription of your topology?
You mentioned that you are running in a AD environment.
Are the DNS Services hosted by the AD's or are they standalones?
i.e. 2 AD (Running DHCP, DNS, IIS,etc...,) , Subnets, etc....
You mentioned that you are running in a AD environment.
Are the DNS Services hosted by the AD's or are they standalones?
i.e. 2 AD (Running DHCP, DNS, IIS,etc...,) , Subnets, etc....
Please take a moment to respond
Did this comment work for you? Yes Partially No Was the comment complete? Yes Partially No Was the comment easy to understand? Yes Partially No Overall, how would you rate this comment? Excellent Good Average SubmitCancel
ID:35766493Author:bsharathDate:05/15 /11 10:14 PMAuthor Comment
Was this comment helpful? Yes No
bsharath:
Sorry but does not show both
I will have machine names. It has to ping machine name and get the ip and then ping the retrieved ip and then get machine name.
I am confused you are trying to get a list of ip --> computer names.
My script will ping a ip-address then connect to that computer via ip-address and return the name of that computer.
Are you able to even connect to these computer WMI ?
If not then my script is useless.
@RobSampson
Your script using NSLOOKUP,right?
If there is a DNS issue whould this work?
Your script using NSLOOKUP,right?
If there is a DNS issue whould this work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@rob
Your script seems to use DNS to resolve an IP-Address, is that correct?
If so think that is "bsharath" real issue.
He would get a false positive on Name to IP.
Your script seems to use DNS to resolve an IP-Address, is that correct?
If so think that is "bsharath" real issue.
He would get a false positive on Name to IP.
Technically yes, even the ping would use a DNS cache, so it could still return false positives. This seems like an odd way to try to fix DNS issues.
Rob.
Rob.
@ Rob
I agree.
That is why my script will at least give you the proper IP to Computer since it is not depending on any DNS info at all.
Strictly ping an IP and if there is a response connect remotely to the WMI and collect the computer name then spit it to the output.
in addition the network is 100% public which is strange also.
I agree.
That is why my script will at least give you the proper IP to Computer since it is not depending on any DNS info at all.
Strictly ping an IP and if there is a response connect remotely to the WMI and collect the computer name then spit it to the output.
in addition the network is 100% public which is strange also.
Yeah, a problem with that though is that the WMI connection can fail anyway if there *is* a DNS issue....
It's a difficult one....
Rob.
It's a difficult one....
Rob.
Really.
I did not know that.
I did not know that.
Yeah, I've seen it happen a few times with some stale DNS records after a PC has not been on for the expiration time of my DHCP reservation. It doesn't happen often, but if you've got DNS issues, then it potentially could.
Rob.
Rob.
Just curious what was the cause of this issue?
ASKER
Did not solve the issue but found all machine has has the issue and manually fixed the dns issues with various solutions
Sounds like you have more of a problem on your hands.
Good luck
Good luck
The attached script found online
http://www.wisesoft.co.uk/scripts/vbscript_ping_all_computers_in_the_domain.aspx
Open in new window