ping源碼windows
Ⅰ windows和linux下ping命令使用的不同之處
1.Windows下默認發送四次數據包,完了之後自己結束,Linux下的ping程序默認不停發送數據包,直到你手動停止.
2.ping命令程序不同,實現ping功能所使用 的源碼不同.
3.返回數據格式不同:
Linux:ping [-dfnqrRv][-c<完成次數>][-i<間隔秒數>][-I<網路界面>][-l<前置載入>][-p<範本樣式>][-s<數據包大小>][-t<存活數值>][主機名稱或IP地址]
Windows:
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
[-r count] [-s count] [[-j host-list] | [-k host-list]]
[-w timeout] target_name
Options:
-t Ping the specified host until stopped.
To see statistics and continue - type Control-Break;
To stop - type Control-C.
-a Resolve addresses to hostnames.
-n count Number of echo requests to send.
-l size Send buffer size.
-f Set Don't Fragment flag in packet.
-i TTL Time To Live.
-v TOS Type Of Service.
-r count Record route for count hops.
-s count Timestamp for count hops.
-j host-list Loose source route along host-list.
-k host-list Strict source route along host-list.
-w timeout Timeout in milliseconds to wait for each reply.
Ⅱ 怎麼在windows開啟ping功能
不用開啟,直接使用就可以,開始--運行--輸入CMD,在打開的窗口中直接輸入PING命令。。詳細的教程請參考http://www.tudoupe.com/,裡面有PING的各種用法。。
Ⅲ 計算機中「Ping」命令的基本工作原理是什麼
Ping發送一個ICMP即網際網路信報控制協議;回聲請求消息給目的地並報告是否收到所希望的ICMPecho(ICMP回聲應答)。它是用來檢查網路是否通暢或者網路連接速度的命令。
作為一個生活在網路上的管理員或者黑客來說,ping命令是第一個必須掌握的DOS命令,它所利用的原理是這樣的:利用網路上機器IP地址的唯一性,給目標IP地址發送一個數據包,再要求對方返回一個同樣大小的數據包來確定兩台網路機器是否連接相通,時延是多少。
ping用於
確定本地主機是否能與另一台主機成功交換(發送與接收)數據包,再根據返回的信息,就可以推斷TCP/IP參數是否設置正確,以及運行是否正常、網路是否通暢等。Ping命令可以進行以下操作:
①通過將ICMP(Internet控制消息協議)回顯數據包發送到計算機並偵聽回顯回復數據包來驗證與一台或多台遠程計算機的連接。
②每個發送的數據包最多等待一秒。
③列印已傳輸和接收的數據包數。
以上內容參考:網路-ping
Ⅳ ping命令怎麼用
ping命令的使用步驟如下:
1.在我們的電腦上面按"win+R"鍵打開運行,在輸入框中輸入cmd,點擊確定。
Ⅳ 【windows里的ping命令該怎麼用呢】
ping是檢測本機對另一主機的網路連通性,發送一個大小為32B的數據包,來觀察本機與另一主機是否網路暢通,數據送達時間是多少等等。如果本機ping一個URL的話,還會自動解析此URL的IP地址。
Ⅵ 在WINDOWS XP中怎樣使用Ping命令
Ping概述: Ping 是Windows系列自帶的一個可執行命令。利用它可以檢查網路是否能夠連通,可以很好地幫助我們分析判定網路故障。該命令只有在安裝了 TCP/IP 協議後才可以使用。Ping命令的主要作用是通過發送數據包並接收應答信息來檢測兩台計算機之間的網路是否連通。當網路出現故障的時候,可以用這個命令來預測故障和確定故障地點。Ping命令成功只是說明當前主機與目的主機之間存在一條連通的路徑。如果不成功,則考慮:網線是否連通、網卡設置是否正確、IP地址是否可用等。 需要注意的是:成功地與另一台主機進行一次或兩次數據報交換並不表示TCP/IP配置就是正確的,你必須執行大量的本地主機與遠程主機的數據報交換,才能確信TCP/IP的正確性。 按照預設設置,Windows上運行的Ping命令發送4個ICMP(網間控制報文協議)回送請求,每個32位元組數據,如果一切正常,你應能得到4個回送應答。 Ping能夠以毫秒為單位顯示發送回送請求到返回回送應答之間的時間量。如果應答時間短,表示數據報不必通過太多的路由器或網路連接速度比較快。Ping還能顯示TTL(Time To Live存在時間)值,你可以通過TTL值推算一下數據包已經通過了多少個路由器:源地點TTL起始值(就是比返回TTL略大的一個2的乘方數)-返回時TTL值。例如,返回TTL值為119,那麼可以推算數據報離開源地址的TTL起始值為128,而源地點到目標地點要通過9個路由器網段(128-119);如果返回TTL值為246,TTL起始值就是256,源地點到目標地點要通過9個路由器網段。 PING命令參數詳解 1、-a 解析計算機NetBios名。 示例: C:\>ping -a 192.168.1.21 Pinging iceblood.yofor.com [192.168.1.21] with 32 bytes of data: Reply from 192.168.1.21: bytes=32 time<10ms TTL=254 Reply from 192.168.1.21: bytes=32 time<10ms TTL=254 Reply from 192.168.1.21: bytes=32 time<10ms TTL=254 Reply from 192.168.1.21: bytes=32 time<10ms TTL=254 Ping statistics for 192.168.1.21: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms 從上面就可以知道IP為192.168.1.21的計算機NetBios名為iceblood.yofor.com。 2、n count 發送count指定的Echo數據包數。 在默認情況下,一般都只發送四個數據包,通過這個命令可以自己定義發送的個數,對衡量網路速度很有幫助,比如我想測試發送50個數據包的返回的平均時間為多少,最快時間為多少,最慢時間為多少就可以通過以下獲知: C:\>ping -n 50 202.103.96.68 Pinging 202.103.96.68 with 32 bytes of data: Reply from 202.103.96.68: bytes=32 time=50ms TTL=241 Reply from 202.103.96.68: bytes=32 time=50ms TTL=241 Reply from 202.103.96.68: bytes=32 time=50ms TTL=241 Request timed out. ……………… Reply from 202.103.96.68: bytes=32 time=50ms TTL=241 Reply from 202.103.96.68: bytes=32 time=50ms TTL=241 Ping st
Ⅶ windows下的ping命令的詳細解釋
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
[-r count] [-s count] [[-j host-list] | [-k host-list]]
[-w timeout] target_name
Options:
-t Ping the specified host until stopped.
To see statistics and continue - type Control-Break;
To stop - type Control-C.
-a Resolve addresses to hostnames.
-n count Number of echo requests to send.
-l size Send buffer size.
-f Set Don't Fragment flag in packet.
-i TTL Time To Live.
-v TOS Type Of Service.
-r count Record route for count hops.
-s count Timestamp for count hops.
-j host-list Loose source route along host-list.
-k host-list Strict source route along host-list.
-w timeout Timeout in milliseconds to wait for each reply.
Ⅷ 如何得到本機ping命令源代碼
一個按扭,一個文本,運行結果到C盤的1.TXT里看看privatesubcommand1_Click()Shell"Cmd.exe/cping"&text1.text&">C:\1.txt",vbHideendsub
Ⅸ 求windows下ping程序c源代碼,模擬的ping也行,能編譯通過就行,網上很多通不過
#pragma pack(4)
#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
#define ICMP_MIN 8 // minimum 8 byte icmp packet (just header)
/* The IP header */
typedef struct iphdr {
unsigned int h_len:4; // length of the header
unsigned int version:4; // Version of IP
unsigned char tos; // Type of service
unsigned short total_len; // total length of the packet
unsigned short ident; // unique identifier
unsigned short frag_and_flags; // flags
unsigned char ttl;
unsigned char proto; // protocol (TCP, UDP etc)
unsigned short checksum; // IP checksum
unsigned int sourceIP;
unsigned int destIP;
}IpHeader;
//
// ICMP header
//
typedef struct _ihdr {
BYTE i_type;
BYTE i_code; /* type sub code */
USHORT i_cksum;
USHORT i_id;
USHORT i_seq;
/* This is not the std header, but we reserve space for time */
ULONG timestamp;
}IcmpHeader;
#define STATUS_FAILED 0xFFFF
#define DEF_PACKET_SIZE 32
#define MAX_PACKET 1024
#define xmalloc(s) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s))
#define xfree(p) HeapFree (GetProcessHeap(),0,(p))
void fill_icmp_data(char *, int);
USHORT checksum(USHORT *, int);
void decode_resp(char *,int ,struct sockaddr_in *);
void Usage(char *progname){
fprintf(stderr,"Usage: ");
fprintf(stderr,"%s [data_size] ",progname);
fprintf(stderr,"datasize can be up to 1Kb ");
ExitProcess(STATUS_FAILED);
}
int main(int argc, char **argv){
WSADATA wsaData;
SOCKET sockRaw;
struct sockaddr_in dest,from;
struct hostent * hp;
int bread,datasize;
int fromlen = sizeof(from);
int timeout = 1000;
char *dest_ip;
char *icmp_data;
char *recvbuf;
unsigned int addr=0;
USHORT seq_no = 0;
if (WSAStartup(MAKEWORD(2,1),&wsaData) != 0){
fprintf(stderr,"WSAStartup failed: %d ",GetLastError());
ExitProcess(STATUS_FAILED);
}
if (argc <2 ) {
Usage(argv[0]);
}
sockRaw = WSASocket (AF_INET,
SOCK_RAW,
IPPROTO_ICMP,
NULL, 0,0);
if (sockRaw == INVALID_SOCKET) {
fprintf(stderr,"WSASocket() failed: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
bread = setsockopt(sockRaw,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,
sizeof(timeout));
if(bread == SOCKET_ERROR) {
fprintf(stderr,"failed to set recv timeout: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
timeout = 1000;
bread = setsockopt(sockRaw,SOL_SOCKET,SO_SNDTIMEO,(char*)&timeout,
sizeof(timeout));
if(bread == SOCKET_ERROR) {
fprintf(stderr,"failed to set send timeout: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
memset(&dest,0,sizeof(dest));
hp = gethostbyname(argv[1]);
if (!hp){
addr = inet_addr(argv[1]);
}
if ((!hp) && (addr == INADDR_NONE) ) {
fprintf(stderr,"Unable to resolve %s ",argv[1]);
ExitProcess(STATUS_FAILED);
}
if (hp != NULL)
memcpy(&(dest.sin_addr),hp->h_addr,hp->h_length);
else
dest.sin_addr.s_addr = addr;
if (hp)
dest.sin_family = hp->h_addrtype;
else
dest.sin_family = AF_INET;
dest_ip = inet_ntoa(dest.sin_addr);
if (argc >2) {
datasize = atoi(argv[2]);
if (datasize == 0)
datasize = DEF_PACKET_SIZE;
}
else
datasize = DEF_PACKET_SIZE;
datasize += sizeof(IcmpHeader);
icmp_data = xmalloc(MAX_PACKET);
recvbuf = xmalloc(MAX_PACKET);
if (!icmp_data) {
fprintf(stderr,"HeapAlloc failed %d ",GetLastError());
ExitProcess(STATUS_FAILED);
}
memset(icmp_data,0,MAX_PACKET);
fill_icmp_data(icmp_data,datasize);
while(1) {
int bwrote;
((IcmpHeader*)icmp_data)->i_cksum = 0;
((IcmpHeader*)icmp_data)->timestamp = GetTickCount();
((IcmpHeader*)icmp_data)->i_seq = seq_no++;
((IcmpHeader*)icmp_data)->i_cksum = checksum((USHORT*)icmp_data,
datasize);
bwrote = sendto(sockRaw,icmp_data,datasize,0,(struct sockaddr*)&dest,
sizeof(dest));
if (bwrote == SOCKET_ERROR){
if (WSAGetLastError() == WSAETIMEDOUT) {
printf("timed out ");
continue;
}
fprintf(stderr,"sendto failed: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
if (bwrote < datasize ) {
fprintf(stdout,"Wrote %d bytes ",bwrote);
}
bread = recvfrom(sockRaw,recvbuf,MAX_PACKET,0,(struct sockaddr*)&from,
&fromlen);
if (bread == SOCKET_ERROR){
if (WSAGetLastError() == WSAETIMEDOUT) {
printf("timed out ");
continue;
}
fprintf(stderr,"recvfrom failed: %d ",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
decode_resp(recvbuf,bread,&from);
Sleep(1000);
}
return 0;
}
/*
The response is an IP packet. We must decode the IP header to locate
the ICMP data
*/
void decode_resp(char *buf, int bytes,struct sockaddr_in *from) {
IpHeader *iphdr;
IcmpHeader *icmphdr;
unsigned short iphdrlen;
iphdr = (IpHeader *)buf;
iphdrlen = iphdr->h_len * 4 ; // number of 32-bit words *4 = bytes
if (bytes < iphdrlen + ICMP_MIN) {
printf("Too few bytes from %s ",inet_ntoa(from->sin_addr));
}
icmphdr = (IcmpHeader*)(buf + iphdrlen);
if (icmphdr->i_type != ICMP_ECHOREPLY) {
fprintf(stderr,"non-echo type %d recvd ",icmphdr->i_type);
return;
}
if (icmphdr->i_id != (USHORT)GetCurrentProcessId()) {
fprintf(stderr,"someone else's packet! ");
return ;
}
printf("%d bytes from %s:",bytes, inet_ntoa(from->sin_addr));
printf(" icmp_seq = %d. ",icmphdr->i_seq);
printf(" time: %d ms ",GetTickCount()-icmphdr->timestamp);
printf(" ");
}
USHORT checksum(USHORT *buffer, int size) {
unsigned long cksum=0;
while(size >1) {
cksum+=*buffer++;
size -=sizeof(USHORT);
}
if(size ) {
cksum += *(UCHAR*)buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (USHORT)(~cksum);
}
/*
Helper function to fill in various stuff in our ICMP request.
*/
void fill_icmp_data(char * icmp_data, int datasize){
IcmpHeader *icmp_hdr;
char *datapart;
icmp_hdr = (IcmpHeader*)icmp_data;
icmp_hdr->i_type = ICMP_ECHO;
icmp_hdr->i_code = 0;
icmp_hdr->i_id = (USHORT)GetCurrentProcessId();
icmp_hdr->i_cksum = 0;
icmp_hdr->i_seq = 0;
datapart = icmp_data + sizeof(IcmpHeader);
//
// Place some junk in the buffer.
//
memset(datapart,'E', datasize - sizeof(IcmpHeader));
}
估計你也試過,網上搜到的。