如何检测网线被拔下、网卡被禁用?局域网内本机网络是否正常工作????
解决方案 »
- sql图片的存储。
- 在线急等-50分,请大家帮忙出出毕业设计的好点子!!
- 那里有powerpdf控件呢?我在google上找了一下PowerPdf 控件,可下载后,只是原码,没有PowerPdf 控件,请问在那里下呢?
- 开仓放粮了—有三条裤衩可以换洗了:)
- 在sendmessage中如何把gettext的内容给一个字符串变量?
- 救命呀,将DataModule打包.bpl后,该怎么在其它Form上用?
- 学生问题!快速解决,在线等待
- 怎样监控icmp包?用自编的程序
- 初学Delphi,请问。。。(解决问题就给分!)
- 怎样实现只有某个控件半透明(不是整个窗体半透明)??
- 求救!!!!!!
- 高手进来讨论个D5文件操作的问题,关于Reset....
如果有个红色的X,表示网线被拔下,如果呈灰色,表示网卡被禁用。
PING其他PC的IP,通则表示LAN是正常工作的
begin
if InternetCheckConnection('http://www.csdn.net/', 1, 0) then
edit1.text:= 'Connected'
else
edit1.text:= 'Disconnected';
end;
这种方法我试过了不行的。
//功能:检测网络是否正常
Function Tfm_angel.CheckNet(IpAddr: string): Boolean;
type PIPOptionInformation = ^TIPOptionInformation;
TIPOptionInformation = packed record
TTL: Byte; // Time To Live (used for traceroute)
TOS: Byte; // Type Of Service (usually 0)
Flags: Byte; // IP header flags (usually 0)
OptionsSize: Byte; // Size of options data (usually 0, max 40)
OptionsData: PChar; // Options data buffer
end; PIcmpEchoReply = ^TIcmpEchoReply; TIcmpEchoReply = packed record Address: DWord; // replying address
Status: DWord; // IP status value (see below)
RTT: DWord; // Round Trip Time in milliseconds
DataSize: Word; // reply data size
Reserved: Word;
Data: Pointer; // pointer to reply data buffer
Options: TIPOptionInformation; // reply options
end; TIcmpCreateFile = function: THandle; stdcall;
TIcmpCloseHandle = function(IcmpHandle: THandle): Boolean; stdcall;
TIcmpSendEcho = function(IcmpHandle: THandle;DestinationAddress: DWord;RequestData: Pointer;RequestSize: Word;RequestOptions: PIPOptionInformation;ReplyBuffer: Pointer;ReplySize: DWord;Timeout: DWord): DWord; stdcall;const
Size = 32;
TimeOut = 500;
var wsadata: TWSAData;
Address: DWord; // Address of host to contact
HostName, HostIP: String; // Name and dotted IP of host to contact
Phe: PHostEnt; // HostEntry buffer for name lookup
BufferSize, nPkts: Integer;
pReqData, pData: Pointer;
pIPE: PIcmpEchoReply; // ICMP Echo reply buffer
IPOpt: TIPOptionInformation; // IP Options for packet to send
const
IcmpDLL = 'icmp.dll';
var hICMPlib: HModule;
IcmpCreateFile : TIcmpCreateFile;
IcmpCloseHandle: TIcmpCloseHandle;
IcmpSendEcho: TIcmpSendEcho;
hICMP: THandle; // Handle for the ICMP Calls
begin
// initialise winsock
Result:=True;
if WSAStartup(2,wsadata) <> 0 then
begin
Result:=False;
halt;
end;
// register the icmp.dll stuff
hICMPlib := loadlibrary(icmpDLL);
if hICMPlib <> null then
begin
@ICMPCreateFile := GetProcAddress(hICMPlib, 'IcmpCreateFile');
@IcmpCloseHandle:= GetProcAddress(hICMPlib, 'IcmpCloseHandle');
@IcmpSendEcho:= GetProcAddress(hICMPlib, 'IcmpSendEcho');
if (@ICMPCreateFile = Nil) or (@IcmpCloseHandle = Nil) or (@IcmpSendEcho = Nil) then
begin
Result:=False;
halt;
end;
hICMP := IcmpCreateFile;
if hICMP = INVALID_HANDLE_VALUE then
begin
Result:=False;
halt;
end;
end
else
begin
Result:=False;
halt;
end;
// ------------------------------------------------------------ Address := inet_addr(PChar(IpAddr));
if (Address = INADDR_NONE) then
begin
Phe := GetHostByName(PChar(IpAddr));
if Phe = Nil then
Result:=False
else
begin
Address := longint(plongint(Phe^.h_addr_list^)^);
HostName := Phe^.h_name;
HostIP := StrPas(inet_ntoa(TInAddr(Address)));
end;
end
else
begin Phe := GetHostByAddr(@Address, 4, PF_INET);
if Phe = Nil then Result:=False;
end;
if Address = INADDR_NONE then
begin
Result:=False;
end;
// Get some data buffer space and put something in the packet to send
BufferSize := SizeOf(TICMPEchoReply) + Size; //
GetMem(pReqData, Size);
GetMem(pData, Size);
GetMem(pIPE, BufferSize);
FillChar(pReqData^, Size, $AA);
pIPE^.Data := pData;
// Finally Send the packet
FillChar(IPOpt, SizeOf(IPOpt), 0);
IPOpt.TTL := 64;
NPkts := IcmpSendEcho(hICMP, Address, pReqData, Size,
@IPOpt, pIPE, BufferSize, TimeOut);
if NPkts = 0 then Result:=False;
// Free those buffers
FreeMem(pIPE); FreeMem(pData); FreeMem(pReqData);
// --------------------------------------------------------------
IcmpCloseHandle(hICMP);
FreeLibrary(hICMPlib);
// free winsock
if WSACleanup <> 0 then Result:=False;
end;