c 實現ping功能

2021-05-22 23:51:46 字數 1101 閱讀 4655

思路

首先新增乙個文字框,用來接收ip位址。用ipaddress myip = ipaddress.parse(textbox1.text.tostring())把文字框內容變成ip位址,寫到乙個異常中,就可以省略掉判斷ip位址是否正確了。

定義乙個ping的方法 system.net.networkinformation.ping p = new system.net.networkinformation.ping()

在定義乙個接收icmp返回的方法接收傳回來的值

system.net.networkinformation.pingoptions optiong = new system.net.networkinformation.pingoptions()

定義好了傳送接收後,定義資料報 string a=「11111111111111111111111111111111111「;

byte buffte=encondig.ascii.getbytes(data); 把定義好的資料報變為2進製**.

int timeout=1000;定義超時時間

peply.address.tostring()  目標ip

peply.roundtriptime.tostring() 返回時間

peply.options.ttl.tostring()  ttl生存週期

peply.buffer.length  資料報大小

**如下:

private void button1_click(object sender, eventargs e)

//listbox1.items.add(peply.address.tostring());

//listbox1.items.add(peply.roundtriptime.tostring());

//listbox1.items.add(peply.options.ttl.tostring());

//listbox1.items.add(peply.options.dontfragment.tostring());

//listbox1.items.add(peply.buffer.tostring());

}catch (exception ex)

C 下實現ping功能

ping的呼叫方法如下 ping mping new ping mping.pinging 127.0.0.1 255,65535 mping.receive 成功接收返回true,timeout 返回false 全部源 如下 using system using system.io using s...

實現PING功能

實現ping功能 具體細節可以看注釋 include include include include include include include include include include include include include define max size 1024 char s...

ping命令的C實現

include include include include include include include include include include include include include include define packet size 1024 define max wai...