Ping Tool

aeathb

n00b
Joined
Jun 3, 2013
Messages
2
Hello there,

I'm new to these forums, but promise I searched around before I made this post! I want to make a VB script like http://hardforum.com/showthread.php?t=1025190, but there is 1 problem. With that script, when a host name is not found, that line is skipped. Is there any way upon finding a non-existent host name that a "unable to find hostnamehere" is included in the output? I'm not very good at scripting, but I'm trying to learn, so please don't get TOO technical!

Thanks in advance
-AE
 
Angry IP Scanner is a free tool you can use, and you can export its findings to several formats (txt, csv). It will list all the IP's you scan for, even if they do not respond (ie the device is powered off or disconnected).
Regarding scripting (or making a script to do it) - sorry, I can't help you there.
 
Try this out:

Code:
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.OpenTextFile("output.txt", 2, True)
Set objHostsFile = objFSO.OpenTextFile("hosts.txt",1)
Do While objHostsFile.AtEndOfStream <> True
	Set objScriptExec = objShell.Exec("ping -a " & objHostsFile.ReadLine & " -n 1")
	Do While objScriptExec.StdOut.AtEndOfStream <> True
		strLine = objScriptExec.StdOut.ReadLine()
		If Left(strLine,7) = "Pinging" Then
			objOutputFile.WriteLine Replace(Right(strLine,Len(strLine) - 8)," with 32 bytes of data:"," was pinged successfully.")
		ElseIf Left(strLine, 12) = "Ping request" Then
			objOutputFile.WriteLine  Replace(strLine," Please check the name and try again.","")
		End If
	Loop
Loop

See if you can figure out why that works. If you want to start learning to code, just start trying things.
 
Depending on your purpose, you might want to look at powershell. All the VB code could be reduced to a couple of lines...

Code:
import-csv csvfile.csv | ? { test-connection $_.hostname -count 1 }

csvfile.csv would look something like this:
Code:
hostname
host1
host2
host3
host4
 
Try this out:

Code:
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.OpenTextFile("output.txt", 2, True)
Set objHostsFile = objFSO.OpenTextFile("hosts.txt",1)
Do While objHostsFile.AtEndOfStream <> True
	Set objScriptExec = objShell.Exec("ping -a " & objHostsFile.ReadLine & " -n 1")
	Do While objScriptExec.StdOut.AtEndOfStream <> True
		strLine = objScriptExec.StdOut.ReadLine()
		If Left(strLine,7) = "Pinging" Then
			objOutputFile.WriteLine Replace(Right(strLine,Len(strLine) - 8)," with 32 bytes of data:"," was pinged successfully.")
		ElseIf Left(strLine, 12) = "Ping request" Then
			objOutputFile.WriteLine  Replace(strLine," Please check the name and try again.","")
		End If
	Loop
Loop

See if you can figure out why that works. If you want to start learning to code, just start trying things.

That is perfect! Thank you Treytech! I didn't realize it was as easy as adding an elseif statement. And I will start looking at power shell in the future, I just want to establish some base before I start moving up.
 
I wouldnt say powershell is moving up. Its just a different language. I tend to write everything I powershell these days because of how all the thing that are exposed so easy.

I would expect powershell to be easier to learn for a beginner too...
 
Back
Top