Kroko Just another WordPress weblog

February 8, 2009

Script to Monitor Your Internet Connection

Filed under: fuck windows — admin @ 5:00 am

this text is from: http://blog.akinstech.com/script-to-monitor-your-internet-connection

Have you ever had a situation where your Internet connection drops for a few seconds, then comes back, then drops again, then comes back, and repeats randomly with no rhyme or reason? Getting your ISP to see the problem can be a real hassle as Murphy’s Law dictates that the problem will ALWAYS go away once you finally get them on the phone. You’ll usually get the standard “looks good on our end” with no actual resolution of the problem. Well, this script will allow you to monitor the line for hours, days, even weeks, and provide you with a timestamped activity log of exactly what was happening over that period. Armed with this type of information, you can usually get your ISP to take notice.

I actually wrote this script a few years ago when one of my clients was having these very problems. Using the log it generates, I was able to provide the ISP with meaningful numbers and exact times, and eventually they were able to correct the problem. Since then, I’ve used it many times to check the stability of a connection. Anyway, today on one of the tech forums, somebody asked how to monitor a flakey line. It got me thinking about this script, so I dusted it off and posted it to the forum. I figured while I was at it, I’d post it here as well.

 

I wrote it in VBScript, and it utilizes the WMI Ping object. Basically it sends a single ping to a host you specify, logs the outcome with a time-stamp, then waits a predetermined delay time and repeats itself indefinitely. If you let this script run for a full day or more, pinging every few seconds, it will give you a really good idea what might be happening with your Internet connection.

The script contains four values that you’ll need to edit:

strHost = “someserver.samplehost.com” – This is the host you want to ping. It can be a web server, a router, a DNS server, etc. You can specify a DNS name or an IP address.
nDelay = 15 – This is how many seconds the script will wait between pings. I find that pinging every 15 seconds is usually sufficient, although you may want to ping as often as every second in some cases.
strLogFile = “C:\Comcastpinglog.txt” – This is the full path to the log you want to create.
nThreshold = 75 – This is the response threshold (in milliseconds). Any ping response which is greater than this will be flagged as “SLOW” and marked as such in the log. This makes it easy to filter these log entries later. 75ms is rather high for most broadband connections at idle. What you’ll want to do is to let the script run for a bit and establish a baseline for what “normal” is. For instance, my Comcast cable connection (3-6Mbit speed) usually pings at about 19-32ms.

What should I ping?
If you’re having trouble with your Internet connection, a good host to ping will be the default gateway provided by your ISP. This would represent the first physical device on the “other side” of your connection. You can get this by checking your router’s “Connection Status” or “WAN Status” screen and noting the IP address for default gateway. Another good one would be one of your ISP’s DNS servers. This is also available in your router. With either of these, you’re pinging something fairly local to your ISP, eliminating additional hops.

If you’re having trouble with your hosted web site or server, you’ll want to ping that server or the IP assigned to you by your provider. Just keep in mind that you will be traversing many hops to get there, so it isn’t uncommon for your provider to pass the blame. If you notice periods of high latency, try to back them up with a tracert output so you can show your provider where slowdown is.

* Note: Please be advised that some ISP’s or network admins may not appreciate you performing continuous pings to their servers. I am not responsible for any nasty emails you might receive. Make sure you know what you’re doing before you go pinging somebody’s else’s servers.

Logfile Output
The script continuously appends to a log file with the following output:

================================================================================
1/26/2008 1:42:16 PM: PINGING HOST: [www.yahoo.com]
================================================================================
1/26/2008 1:42:16 PM: Reply from 209.131.36.158: bytes=32 time=19ms TTL=51
1/26/2008 1:42:21 PM: Reply from 209.131.36.158: bytes=32 time=20ms TTL=52
1/26/2008 1:42:26 PM: Ping Failed
1/26/2008 1:42:31 PM: Ping Failed
1/26/2008 1:42:36 PM: Ping Failed
1/26/2008 1:42:41 PM: Reply from 209.131.36.158: bytes=32 time=39ms TTL=51 SLOW
1/26/2008 1:42:46 PM: Reply from 209.131.36.158: bytes=32 time=23ms TTL=51
1/26/2008 1:42:51 PM: Reply from 209.131.36.158: bytes=32 time=31ms TTL=51 SLOW

The log is appended infinitely, so you’ll eventually want to purge the log or copy it off to avoid it growing to an unmanageable size.

You may later filter specific lines from the log using the following DOS commands:

type logfile.txt | find /I "Failed" > failed.txt
type logfile.txt | find /I "SLOW" > slow.txt

Running the Script
Copy the VBScript code below and paste into a VBS file in your scripts directory. Call it PingTest.vbs. To run the script, launch it with the command “cscript PingTest.vbs”. To kill the script, just press CTRL-C. Note: Do NOT just double-click the script to run it! That will cause it to launch with the wscript engine. Since this script outputs to the console it needs to run with the cscript engine.

To make things easier, and ensure you always launch it with cscript, just write a simple 2-line batch file to launch the script. (Put it in the same directory as the vbs script):

PingTest.bat

@echo off
cscript %~dp0PingTest.vbs

PingTest.vbs

Dim strHost, nDelay, strLogFile, nThreshold

' EDIT THESE VARIABLES TO SUIT YOUR APPLICATION
strHost = "someserver.samplehost.com" ' What do you want to ping
nDelay = 15  ' How many seconds to pause between pings
strLogFile = "C:\Comcastpinglog.txt" ' Full Name and Path of logfile
nThreshold = 75 ' Anything response over this (in ms) will be flagged as "Slow"

Dim txtLogLine, objPing, objRetStatus, rc

rc = LogLine(strLogFile,"================================================================================")
rc = LogLine(strLogFile,FormatDateTime(Now(),0) & ": PINGING HOST: [" & strHost & "]")
rc = LogLine(strLogFile,"================================================================================")

Do While True
   txtLogLine = ""

   txtLogLine = txtLogLine & FormatDateTime(Now(),0) & ": "
   Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
       ("select * from Win32_PingStatus where address = '" & strHost & "'")

   For each objRetStatus in objPing
       If IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
          Ping = False
          txtLogLine = txtLogLine & "Ping Failed"
       Else
          Ping = True
	  txtLogLine = txtLogLine & "Reply from " & objRetStatus.ProtocolAddress & ": "
	  txtLogLine = txtLogLine & "bytes=" & objRetStatus.BufferSize & " "
          txtLogLine = txtLogLine & "time=" & objRetStatus.ResponseTime & "ms "
          txtLogLine = txtLogLine & "TTL=" & objRetStatus.ResponseTimeToLive
	  If objRetStatus.ResponseTime >= nThreshold Then
	     txtLogLine = txtLogLine & " SLOW"
	  End If
       End If
   Next
   WScript.Echo txtLogLine
   rc = LogLine(strLogFile, txtLogLine)
   WScript.Sleep nDelay * 1000
Loop

Function LogLine(strFile, strLine)
   Dim objFSO, objFile
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFile = objFSO.OpenTextFile(strFile,8,True)
   objFile.WriteLine(strLine)
   objFile.Close
End Function

While this isn’t necessarily the most advanced method of detecting a slow connection, it’s surprisingly accurate in exposing periods of high latency or dropped connection. Try it out and let me know what you think.

January 17, 2009

Multiple Remote Desktop Connections (RDC) XP not working

Filed under: fuck windows — admin @ 6:55 am

Download link: http://ice-club.com.ua/antiwpa/Other/TermSrvNoRestrPatch-1-3/

 

now the story:

 

If you have tweaked around with Windows XP you probably know that its possible to connect to another system across a network, intranet / internet as a remote user with the same interface as sitting on the system.

The capability is bundled with XP pro and I’m sure that you will find enough and more blogs / tutorial about how it works with screenshots and all. The issue is that its not available in XP Home and in XP Pro it allows only one user to work on the computer.

Based on my searches I believe its also possible to hack XP Home to support RDC, though I haven’t tried it myself the following link does have all the details that you could possibly need to try this out.

http://www.geekport.com/2007/08/15/enabling-remote-desktop-in-xp-home/

http://www.mydigitallife.info/2008/06/14/install-and-enable-remote-desktop-in-windows-xp-home-edition/

Now to the problem in XP pro , as mentioned earlier , the licencing agreement of MS allows only one user to access the computer so if you RDC to a computer the existing user gets logged out (not desirable). There is a way of overcoming this issue with some registry changes and a changed Terminal Service Dynamic Link Library (termserv.dll).

There are detailed article on the procedure available below

http://sig9.com/articles/concurrent-remote-desktop

http://www.mydigitallife.info/2008/06/13/enable-multiple-concurrent-remote-desktop-connections-or-sessions-in-windows-xp/

Additional some good soul has also written a program that neatly makes all these changes and also patches the termserv.dll the link for that is

http://www.kood.org/terminal-server-patch/

For most of the people in the world doing all this worked just fine and if you have tried and are successful good for you …. but then again there are those who are not so fortunate in life such as me who after trying out each and everything on all the links that I have posted including the application got nothing to work. The main user still got logged out each time I tried to RDC to the system.

After more googling I came across this obscure little package called
TermSrvNoRestrPatch-1-3

The location of the file is as following

http://ice-club.com.ua/antiwpa/Other/TermSrvNoRestrPatch-1-3/

which was also a real pain to find a valid link for it. It worked like a charm, it step by step patched all the file which the other application also did but this one got it to work ! It also patched the capability to RDC to a local host, yes there are a few reason why someone would want to do something like this 🙂 such as running multiple instances of a single program.

A word of caution, since the code edits few of the windows’ files, some antivirus programs through it up as a virus. You may need to run this in safemode if your antivirus prevents its from executing and more importantly if your convinced that it isn’t a virus.

Hope this has helped all the hapless people out there trying to get this to work. As always do drop me a comment if you found this useful, click an ad if your feeling generous !

hide console window run by task scheduler

Filed under: fuck windows — admin @ 6:54 am

JW> Hi, I am using Win2000 scheduler to run a .CMD ( batch ) file every
JW> minute. The console window is pop up everytime when the batch file is
JW> launched. Is is possible to tell scheduler hide the console window some
JW> how?

This WSH/VBScript will run your batch file in a hidden window.

‘MyCmd.vbs
Set WshShell = WScript.CreateObject(“WScript.Shell”)
cmd = “C:\bin\scripts\MyCmd.cmd”
Return = WshShell.Run(cmd, 0, True)
set WshShell = Nothing

« Newer PostsOlder Posts »

Powered by WordPress