Welcome![Sign In][Sign Up]
Location:
Search - pinging

Search list

[TCP/IP stackPinging

Description: Ping程序的简单实现.用RAW形式的Socket,用到了IP协议和ICMP协议
Platform: | Size: 9941 | Author: gto9999 | Hits:

[Internet-Network一个判断远程主机存活程序代码

Description: 一个判断远程主机存活程序代码(ping) #include #include #include #include #include "winsock.h" #pragma comment(lib,"Ws2_32"); #define SEND_SIZE 32 #define PACKET_SIZE 4096 #define ICMP_ECHO 8 #define ICMP_ECHOREPLY 0 struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; unsigned short icmp_id; unsigned short icmp_seq; unsigned long icmp_data; }; struct ip { unsigned char ip_hl:4; unsigned char ip_v:4; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; unsigned long ip_src; unsigned long ip_dst; }; unsigned char sendpacket[PACKET_SIZE]; unsigned char recvpacket[PACKET_SIZE]; struct sockaddr_in dest_addr; struct sockaddr_in from_addr; int sockfd; int pid; unsigned short cal_chksum(unsigned short *addr,int len); int pack(int pack_no); int unpack(unsigned char *buf,int len); void send_packet(void); void recv_packet(void); void main(int argc,char *argv[]) { struct hostent *host; struct protoent *protocol; WSADATA wsaData; int timeout=1000; int SEND_COUNT=4; int i; char *par_host; par_host=argv[argc-1]; //IP赋值 switch(argc) { case 2: break; case 3: if(strcmp(argv[1],"-t")==0) { SEND_COUNT=10000; break; } //fall through default: printf("usage: %s [-t] Host name or IP address\n",argv[0]); exit(1); } if(WSAStartup(0x1010,&wsaData)!=0) { printf("wsastartup error\n"); exit(1); } if( (protocol=getprotobyname("icmp") )==NULL) { printf("getprotobyname error\n"); exit(1); } /* printf("%s\n",protocol->p_name); printf("%s\n",protocol->p_aliases); printf("%d\n",protocol->p_proto); system("pause"); */ if( (sockfd=socket(AF_INET,SOCK_RAW,protocol->p_proto) )<0) { printf("socket error\n"); exit(1); } if(setsockopt(sockfd,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,sizeof(timeout))h_length); //resolve address to hostname if(host=gethostbyaddr(host->h_addr,4,PF_INET)) par_host=host->h_name; // //printf("%s\n",par_host); // } else if( dest_addr.sin_addr.s_addr=inet_addr(par_host)==INADDR_NONE) { printf("Unkown host %s\n",par_host); exit(1); } pid=getpid(); /* printf("%d\n",pid); system("pause"); */ printf("Pinging %s [%s]: with %d bytes of data:\n\n",par_host,inet_ntoa(dest_addr.sin_addr),SEND_SIZE); for(i=0;i1) { sum+=*w++; nleft-=2; } if( nleft==1) { *(unsigned char *)(&answer)=*(unsigned char *)w; sum+=answer; } sum=(sum>>16)+(sum&0xffff); sum+=(sum>>16); answer=~sum; return answer; } //打包 int pack(int pack_no) { int packsize; struct icmp *icmp; packsize=8+SEND_SIZE; icmp=(struct icmp*)sendpacket; icmp->icmp_type=ICMP_ECHO; icmp->icmp_code=0; icmp->icmp_cksum=0; icmp->icmp_seq=pack_no; icmp->icmp_id=pid; icmp->icmp_data=GetTickCount(); icmp->icmp_cksum=cal_chksum( (unsigned short *)icmp,packsize); /*校验算法*/ return packsize; } //解包 int unpack(unsigned char *buf,int len) { struct ip *ip; struct icmp *icmp; double rtt; int iphdrlen; ip=(struct ip *)buf; iphdrlen=ip->ip_hl*4; icmp=(struct icmp *)(buf+iphdrlen); if( (icmp->icmp_type==ICMP_ECHOREPLY) && (icmp->icmp_id==pid) ) { len=len-iphdrlen-8; rtt=GetTickCount()-icmp->icmp_data; printf("Reply from %s: bytes=%d time=%.0fms TTL=%d icmp_seq=%u\n", inet_ntoa(from_addr.sin_addr), len, rtt, ip->ip_ttl, icmp->icmp_seq); return 1; } return 0; } //发送 void send_packet() { int packetsize; static int pack_no=0; packetsize=pack(pack_no++); if( sendto(sockfd,(char *)sendpacket,packetsize,0,(struct sockaddr *)&dest_addr,sizeof(dest_addr) )=0) success=unpack(recvpacket,n); else if (WSAGetLastError() == WSAETIMEDOUT) { printf("Request timed out.\n"); return; } }while(!success); } UID5380 帖子239 精华0 积分1289 阅读权限40 来自软件学院 在线时间81 小时 注册时间2006-5-22 最后登录2007-2-24 查看详细资料 TOP
Platform: | Size: 5881 | Author: shuiyuan313 | Hits:

[TCP/IP stackPinging

Description: Ping程序的简单实现.用RAW形式的Socket,用到了IP协议和ICMP协议-Ping procedure simple to achieve. With RAW form of Socket, use the IP protocol and the ICMP protocol
Platform: | Size: 10240 | Author: gto9999 | Hits:

[Delphi VCLping

Description: delphi routine for pinging ip
Platform: | Size: 61440 | Author: iman10012002 | Hits:

[WEB Codecom_ping

Description: Ping 1.0.0 is a component for pinging xml-rpc updating services (such as rpc.weblogs.com or rpc.technorati.com). To ping just select “Component - Ping - Ping” at the backend. You can edit list of rpc servers which to ping.-Ping 1.0.0 is a component for pinging xml-rpc updating services (such as rpc.weblogs.com or rpc.technorati.com). To ping just select “Component- Ping- Ping” at the backend. You can edit list of rpc servers which to ping.
Platform: | Size: 4096 | Author: Denis | Hits:

[SCMNEtscanner

Description: ping utility used for pinging proxy
Platform: | Size: 126976 | Author: Karthik J S R | Hits:

[Internet-NetworkPING.ZIP

Description: pinging the site through a program
Platform: | Size: 9216 | Author: richa | Hits:

[Sniffer Package capturePing

Description: ping to find icmp file connection between one pc to another .. once it reaches de distinction it will give u de acknowledgment data.-pinging to find icmp file connection between one pc to another .. once it reaches de distinction it will give u de acknowledgment data.
Platform: | Size: 278528 | Author: sreag | Hits:

[Internet-Networkne-dia

Description: SAMPLE WINSOCK PINGING
Platform: | Size: 39936 | Author: mion | Hits:

[Internet-NetworkWinPing

Description: Windows下Ping程序 测试有效连接。 输入一个网址或一个有效的主机名,例如http://www.google.com或者google.com,或者一个有效的IP地址,例如: 72.14.207.99(google.com)。 IP地址转换成主机名,反之亦然。一个空的输入给本地IP地址。按钮“选项...”打开WinPing选项:无限循环(ping运行在一个无限循环,并显示平均实时),Multiping(ping一前一后),重试次数,超时时间以毫秒为单位,显示的响应时间的平均值,显示日期的ping和时间,显示的主机或IP地址的国家名称-Ping program useful to test your connection. Enter a web address or a valid host name, e.g. http://www.google.com or google.com, or a valid IP address, e.g. 72.14.207.99 (google.com). The IP addresses are converted into host names and conversely. A empty input gives local IP address. The button "Options..." opens the WinPing options: Infinite Loop (runs pings in a infinite loop and shows the average in real time), Multiping (for several pings one after the other), Number of Retries, Timeout in milliseconds, Displaying the Average of the response times, Displaying Date and Time of the ping, Displaying Country Name of host or IP address... The "Auto-Save" option will allow you to save thousands of lines of pinging information (in Infinite Loop Mode). This program requires the Microsoft .NET Framework version 2.0 or higher.
Platform: | Size: 4418560 | Author: love | Hits:

[TCP/IP stackPingOriginal_MikeMuuss_1983

Description: Ping original program. implement pinging test
Platform: | Size: 5120 | Author: hectorin5000 | Hits:

CodeBus www.codebus.net