- 浏览: 99772 次
- 性别:
- 来自: 深圳
最新评论
-
zpap:
这样的的设置好像是有问题的..
JDK环境变量配置小工具 -
qiaoxia_lan:
都不能访问,这是怎么回事啊。
为JAVA爱好者提供了超过400本电子书和3部视频 -
Tortoise:
最好多一些视频文件,个人感觉比较好一点
为JAVA爱好者提供了超过400本电子书和3部视频 -
skj198568:
看看了,好书还不少。
为JAVA爱好者提供了超过400本电子书和3部视频 -
njuptsoz:
谢谢分享!
JDK环境变量配置小工具
/******************************************************************************\
* ping.c - Simple ping utility using SOCK_RAW
*
* This is a part of the Microsoft Source Code Samples.
* Copyright 1996-1997 Microsoft Corporation.
* All rights reserved.
* This source code is only intended as a supplement to
* Microsoft Development Tools and/or WinHelp documentation.
* See these sources for detailed information regarding the
* Microsoft samples programs.
\******************************************************************************/
#pragma pack(4)
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#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:\n");
fprintf(stderr,"%s <host> [data_size]\n",progname);
fprintf(stderr,"datasize can be up to 1Kb\n");
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\n",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\n",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\n",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\n",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\n",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\n",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\n");
continue;
}
fprintf(stderr,"sendto failed: %d\n",WSAGetLastError());
ExitProcess(STATUS_FAILED);
}
if (bwrote < datasize ) {
fprintf(stdout,"Wrote %d bytes\n",bwrote);
}
bread = recvfrom(sockRaw,recvbuf,MAX_PACKET,0,(struct sockaddr*)&from,
&fromlen);
if (bread == SOCKET_ERROR){
if (WSAGetLastError() == WSAETIMEDOUT) {
printf("timed out\n");
continue;
}
fprintf(stderr,"recvfrom failed: %d\n",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\n",inet_ntoa(from->sin_addr));
}
icmphdr = (IcmpHeader*)(buf + iphdrlen);
if (icmphdr->i_type != ICMP_ECHOREPLY) {
fprintf(stderr,"non-echo type %d recvd\n",icmphdr->i_type);
return;
}
if (icmphdr->i_id != (USHORT)GetCurrentProcessId()) {
fprintf(stderr,"someone else's packet!\n");
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("\n");
}
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));
}
发表评论
-
为JAVA爱好者提供了超过400本电子书和3部视频
2009-01-10 14:20 2443http://www.ibook8.com/book/java ... -
http://blog.csdn.net/ycw/
2008-08-08 15:52 817http://blog.csdn.net/ycw/ ... -
WinCVS与CVSNT简明使用手则
2008-08-08 15:51 1204WinCVS与CVSNT简明使用手 ... -
WinCVS与CVSNT简明使用手则
2008-08-08 15:50 11111、前言:CVS是版本控制 ... -
CVS使用手册(推荐)
2008-08-08 15:47 1249版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出 ... -
用cvs实现复杂的权限控制
2008-08-08 15:46 3468作者:张元一这篇文章的基础是:为CVS建立只读用户,如果你对C ... -
CVSNT用户管理方案
2008-08-08 15:46 1096所有这些操作基于的环境和软件版本:WINDOWS2000 Pr ... -
CVS中增加目录及标签和分支
2008-08-08 15:44 30281.在cvs中增加目录. 如果要在CVS中增加一个目录层,而不 ... -
CVS权限设置
2008-08-08 15:43 2245不同用户设置不同的访 ... -
关于CVS在Window2000下的权限管理
2008-08-08 15:40 866一. CVS版本问题 CVS分开客户端和服务器端两个程序 ... -
数据感知控件之浮想联翩
2008-07-19 15:44 1048Delphi制作数据感知控件之浮想联翩 知识点本文共有6个关于 ... -
SQL备份
2008-07-17 10:01 758备份: backupsql := 'backup databa ... -
SQL导入/导出Excel
2008-07-17 10:01 1130这是在CSDN上邹键的东 ... -
portscan程序代码
2008-06-25 16:33 837#include <afxext.h> #incl ... -
CIH 1.4源程序
2008-06-25 16:32 770CIH 1.4源程序 信息来源:黑客防线; ********* ... -
ARP攻击软件源码
2008-06-25 16:29 1330/****************************** ... -
MD5破解相关MAKE.bat
2008-06-25 16:27 1012信息来源:xfocus z:\md5coll>MAKE ... -
一段隐藏文件的C++程序源代码
2008-06-25 16:25 2653#include <iostream>#inclu ... -
TCP多线程正向后门源代码
2008-06-25 16:23 1179#!usr/bin/perl -w #duo_xian_nc. ... -
简易Telnet后门源代码
2008-06-25 16:19 1888/////////////////////////////// ...
相关推荐
microsoft ping命令源代码
ping命令源代码,超清晰注释,结构清晰明白
微软Ping源代码,帮助学习ICMP协议
VB Ping 命令源代码,全部以API函数实现,可用于底层分析IP数据
C++编写的ping程序源代码,C++编写的ping程序源代码
本资源是一个工程,可以用,那个两分的是骗人的
可视化PING命令工具,基于Delphi开发的源代码,在DOS方式,利用Ping命令我们可以方便的知道网络连接状态,这里我们在Windows下实现同样的功能。输入网址,配置好循环时间和超时时间,程序可以定时对网址进行Ping操作...
微软ping命令的源代码,代码虽小 但是值得看
[VC]微软ping程序源代码完整版 int main(int argc, char **argv){ WSADATA wsaData; SOCKET sockRaw; struct sockaddr_in dest,from; struct hostent * hp; 。。。
windows命令ping的源代码,大家可以学习学习,写自己的网络连接测试程序哟
终于找到了: 部分内容 <br/>ping的源代码 <br/>#pragma pack(4) #define WIN32_LEAN_AND_MEAN #include #include #include #define ICMP_ECHO 8 #define ICMP_ECHOREPLY 0 ...
实现Ping的源代码,基础c语言学习非常好。
pb实现ping命令代码,已在pb8中调试通过
linux内核2.6系统中开源Ping源代码
Ping命令源代码,学习对ICMP包的填充
// This sample illustrates how an ICMP ping app can be written // using the SOCK_RAW socket type and IPPROTO_ICMP protocol. // By creating a raw socket, the underlying layer does not change // the ...
自己写的Linux下的ping的简单原型,只有一个函数一个循环,几乎没有出错处理,不过结构清晰易懂,适合希望迅速理解ICMP实现Ping的人。
广东工业大学计算机网络课设 ping程序的源代码 自行打包即可使用!
网络命令ping的源代码,希望对你有用。unix/linux下直接可以用,Qnx下做轻微修改就可以用