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));
}
估计你也试过,网上搜到的。