if GetSystemMetrics(SM_NETWORK) AND $01 = $01 then
ShowMessage('Machine is attached to network')
else
ShowMessage('Machine is not attached to network');
function GetLocalIP:string;
var
WSAData:TWSAData;
HostName:array[0..MAX_COMPUTERNAME_LENGTH] of Char;
HostEntHostEnt;
LastIPInAddr;
IPList:^PInAddr;
begin
Result:='';
if 0=WSAStartup(MAKEWORD(1,1),WSAData) then
try
if 0=gethostname(HostName,MAX_COMPUTERNAME_LENGTH+1) then
begin
HostEnt:=gethostbyname(HostName);
if HostEnt<>nil then
begin
IPList:=Pointer(HostEnt^.h_addr_list);
repeat
LastIP:=IPList^;
INC(IPList);
until IPList^=nil;
if LastIP<>nil then
Result:=inet_ntoa(LastIP^);
end;
end;
finally
WSACleanup;
end;
end;
如果GetLocalIP='127.0.0.1'那么就是断线了或网络没有启动起来,我试过 n 次了