I've been working on a program in c# that will let me monitor plenty of information about my system, a part of it the network stat, including mostly of internet speed, ping time and external ip.
This could also be used as an example for the ticks and timers in the system.
I'm using a big site in my country for the speeds, so you should fit the "www.ynet.co.il" to one the fit your needs better, and the ip is from a specific address at http://www.whatismyip.com
The form is composed of a single label named label1 to display the results.
void MainFormLoad(object sender, EventArgs e)
{
long tick;
//pinging
System.Net.NetworkInformation.Ping png=new System.Net.NetworkInformation.Ping();
png.Send("www.ynet.co.il");//static ping to create the classes
tick=DateTime.Now.Ticks;
for (int i=0;i<4;i++)
png.Send("www.ynet.co.il");
tick=(DateTime.Now.Ticks-tick)/4;
label1.Text="ping="+(((double)tick)/TimeSpan.TicksPerMillisecond).ToString()+"ms\n";
System.Net.WebClient wc=new System.Net.WebClient();
//getting speeds:
string site;
tick=DateTime.Now.Ticks; //these 3 lines must remain close to each
site=wc.DownloadString("http://www.ynet.co.il/"); //2
tick=DateTime.Now.Ticks-tick; //3
//label1.Text+="time="+((tick)/TimeSpan.TicksPerMillisecond).ToString()+" ms\n";
string tmp=((site.Length/1024)/((double)tick/TimeSpan.TicksPerSecond)).ToString("g4");
label1.Text+="speed="+tmp+" kb/s (for size="+(site.Length/1024).ToString()+" kb)\n";
//getting ip address
tmp=wc.DownloadString("http://www.whatismyip.com/automation/n09230945.asp"); //this address get ip directly
label1.Text+="external ip="+tmp;
}
If you want to know about a specific part of the program, feel free to ask.
Tuesday, 5 January 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment