cping.h
// ping.h: inte***ce for the cping class.
////
#if !defined(afx_ping_h__2ebf2c11_a0a3_403b_9eb2_1905cff8ee58__included_)
#define afx_ping_h__2ebf2c11_a0a3_403b_9eb2_1905cff8ee58__included_
#if _msc_ver > 1000
#pragma once
#endif // _msc_ver > 1000
#include#include#include#pragma comment(lib,"ws2_32.lib")
#define icmp_echoreply 0
#define icmp_echoreq 8
//typedef struct tagipdr
iphdr,*piphdr;//rfc791 的ip協議頭型別
typedef struct tagicmp
icmphdr,*picmphdr;//rfc 792 icmp協議頭
/#define req_datasize 32
typedef struct tagechorequest
echorequest,*pechorequest;//請求回傳的資料長度
///typedef struct tagechoreply
echoreply,*pechoreply;//回送請求報文
// 用於ping的探測技術
class cping
;#endif // !defined(afx_ping_h__2ebf2c11_a0a3_403b_9eb2_1905cff8ee58__included_)
cping.cpp
// ping.cpp: implementation of the cping class.
////
#include "stdafx.h"
#include "ping.h"
#ifdef _debug
#undef this_file
static char this_file=__file__;
#define new debug_new
#endif
//// construction/destruction
//cping::cping()
cping::~cping()
void cping::initping()
if(wsadata.wversion!=version) }
void cping::cleanup()
// 列印錯誤的**
void cping::reporterror(lpcstr psrtfrom)
// 等待回應資訊
int cping::waitforechoreply(socket s)
//傳送請求資訊
int cping::sendechorequest(socket s,lpsockaddr_in lpsttoaddr)
if(nleft==1)
sum=(sum>>16)+(sum&0xffff);
sum+=(sum>>16);
answer=~sum;
return answer;
}// 探測某ip位址
bool cping::ping(cstring strip)
lphost=gethostbyname(strip);
if(lphost==null)
sadest.sin_addr.s_addr=*((u_long far*)(lphost->h_addr));
sadest.sin_family=af_inet;
sadest.sin_port=0;
//printf("\n探測主機%s[%s]:%d位元組\n",strip,inet_ntoa(sadest.sin_addr),req_datasize);
int ncount = 0;
for(nloop=0;nloop<4;nloop++)
if(!nret)
dwtimesent=recvechoreply(rawsocket,&sasrc,(char*)&cttl);
dwelapsed=time-dwtimesent;
ncount ++;
} closesocket(rawsocket);
if(ncount > 2)
return true;
return false;
}// 將長整性的ip位址,轉換成字串型
cstring cping::longiptostr(long nip)
// 將字串型的ip位址,轉換成長整性
long cping::striptolong(cstring strip)
呼叫**:
cping ping;
bool flag = false;
flag = ping.ping("172.0.0.1");
C 編寫乙個不可複製的類
c 編寫乙個不可複製的類 flyfish effective c 條款06 若不想使用編譯器自動生成的函式,就該明確拒絕 explicitly disallow the use of complier generated functions you do not want.老式c 的寫法 class...
發布乙個modern c 編寫的網路庫
uv cpp是乙個基於libuv的c 封裝網路庫,基於本人實際專案需求開發並使用。介面較為簡單易用,並對libuv一些特性做了擴充套件及優化。壓測結果穩定 高效。暫未發現記憶體洩漏及崩潰等相關bug。截至目前,c 沒有標準網路庫,常見的有ace和boost.asio。ace較為龐大臃腫,封裝複雜,個...
PING 乙個網段
dos windows的命令列 批處理 for l p in 1,1,254 do ping 192.168.1.p n 1 find reply from i 在dos視窗執行上面的批命令,就會顯示出任何開機的ping結果.假如顯示ping不通的任何結果,則命令為 for l p in 1,1,2...