|
Answer» I am working on a VBS script to help troubleshoot an intermittent network / internet PROBLEM, and I was hoping to get some ideas from PROGRAMMERS who may have done something similar.
I don't even have any specific details on the intermittent problem that I am writing this for, but I decided that I would just make it generic as I will probably be able to use it in the future. All I know about the current issue is that she keeps having intermittent problems connecting to the internet, and that she is using a wireless network card. My code so far is basically: check for ICMP echo reply from known IP addresses from close to far, check DNS by pinging hostname, check wireless signal strength. It basically goes like this so far: Ping local machine Ping other computer on LAN Ping gateway / router Ping DNS server Ping REMOTE IP Ping remote hostname Check wireless signal strength (via WMI) Log anything that fails, and loop every 30 seconds
I'm sure that there are a lot more things that could be checked, but I'm not sure what or where to look. If anybody has any ideas and / or code samples of what to check or how to check it, please let me know.Gary,
This snippet may help with the pings. Modify it as you will; you can add additional if statements and log the results accordingly.
Code: [Select]Const ForWriting = 2 Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile ("c:\Logfile.txt", ForWriting, True)
Do While True If PingOK("127.0.0.1") = False Then LogError("Cannot reach local machine") ' ' add other ping tests here along with log message ' WScript.Sleep 30000 Loop
f.Close
Function PingOK(Machine) Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._ ExecQuery("select * from Win32_PingStatus where address = '"_ & machine & "'") PingOK = 1 For Each objStatus in objPing If IsNull(objStatus.StatusCode) or objStatus.StatusCode <> 0 Then PingOK = 0 End If Next End Function
Sub LogError(msg) f.WriteLine msg End Sub
Signal strength was another story. You can ACCESS it thru the root\wmi namespace using the MSNdis_80211_ReceivedSignalStrength class. The result is a db value that I don't know how to convert to Mbps.
Hope this helps. Thanks, Sidewinder. I actually already have code for the pings and signal strength and logging failures. That all works, but it just seems kind of lame for a network test program because it doesn't seem to test very much to me.
I didn't know if there are more things that could be easily tested. One thing that I did look for but couldn't get to work was if there was a way to detect / log the LAN connection speed - like when you look at your network properties, and it says "Speed: 100.0 Mbps". I found a WMI query for Win32_NetworkAdapter and there was a "speed" property, but I can't get any info from it.
I just thought somebody might have additional ideas like "you can check for dropped network packets and retries with this code" or "a good network test is to use netsh.exe to look for this".
Thanks for the code and help, and please let me know if you have any additional ideas.Not really any new ideas. WMI seems to be trial and error at best. I still like the MSNdis_80211_ReceivedSignalStrength class, if only because it is volatile enough that it may give some hint of impending problems.
A suggestion would be to write it as some sort of a monitor script, so only when the value does change would the log be updated. You could also attempt the pings at this time.
Code: [Select]strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI") Set colEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceModificationEvent WITHIN 3 WHERE " _ & "Targetinstance ISA 'MSNdis_80211_ReceivedSignalStrength' And " _ & "Targetinstance.Ndis80211ReceivedSignalStrength > -54") Do Set objEvent = colEvents.NextEvent() WScript.Echo "Signal Strength Modified:", _ objEvent.TargetInstance.Ndis80211ReceivedSignalStrength ' ' Put your pings here ' Loop
The value on my 802.11g wireless connection varies from -53 to -57, so you may have to play around with the hardcoded value. From what I can tell, the closer to zero the value, the worse the connection.
Let us know how you make out.
Yes, thanks. I played around with it for a while last weekend. The best I could tell from my testing, the values seemed to range from -10 dBm (perfect) to -102 dBm (too weak to do anything). I also NOTICED the -10 would also sometimes show up when there was no signal strength. My testing concluded that: -11 to -29 is great -30 to -47 is good -48 to -65 is OK -66 to -82 is poor -83 to -102 is worthless
Here is my code if anybody is interested: Code: [Select]Function CheckWireless() Signal = GetSignalStrength() SSID = GetSSID() APMac = GetAPMac() SigPct = round((Signal+102)/.92) if Signal > -11 Then QualityStr = "Suspicious" elseif Signal > -29 Then QualityStr = "Excellent" elseif Signal > -47 Then QualityStr = "Good" elseif Signal > -65 Then QualityStr = "Acceptable" elseif Signal > -82 Then QualityStr = "Poor" elseif Signal >= -102 Then QualityStr = "Worthless" else QualityStr = "Suspicious" end if LogString = now & ": WiFi signal is " & Signal & " dBm (" & QualityStr & " at " _ & SigPct & "%) from AP " & chr(34) & SSID & chr(34) & " MAC=" & APMac call LogToFile(Pass, LogString) if Signal > -11 Then call LogToFile(Fail, LogString) elseif Signal < -75 Then call LogToFile(Fail, LogString) end if End Function I am testing with more wireless cards now, and the Ndis80211ReceivedSignalStrength range appears to depend on the driver. I tried a different card, and the values range from -45 to -90.
|