admin 管理员组

文章数量: 1086019


2024年4月18日发(作者:ascii是什么代码)

获得及设置本机的ip地址,子网掩码,网关,dns服务器信息

(Delphi)

1、//取IP地址

function GetIP : string;

type

TaPInAddr = array [0..10] of PInAddr;

PaPInAddr = ^TaPInAddr;

var

phe : PHostEnt;

pptr : PaPInAddr;

Buffer : array [0..63] of char;

I : Integer;

GInitData : TWSADATA;

begin

WSAStartup($101, GInitData);

Result := '';

GetHostName(Buffer, SizeOf(Buffer));

phe :=GetHostByName(buffer);

if phe = nil then Exit;

pptr := PaPInAddr(Phe^.h_addr_list);

I := 0;

while pptr^[I] <> nil do begin

result:=StrPas(inet_ntoa(pptr^[I]^));

Inc(I);

end;

WSACleanup;

end;

2、获取路由、网关信息、网卡信息:

Procedure 1Click(Sender:TObject);

begin

;

if FileExists(Temp) then

DeleteFile(Temp);

WinExec(PChar('

print >'+Temp),SW_HIDE);

while not FileExists(Temp) do

Sleep(1000)

Try

omFile(Temp);

except

end;

end;

3、所有信息

function LocalIP:string;

type

TaPInAddr = array [0..10] of PInAddr;

PaPInAddr = ^TaPInAddr;

var

phe : PHostEnt;

pptr : PaPInAddr;

Buffer : array [0..63] of char;

I : Integer;

GInitData : TWSADATA;

begin

WSAStartup($101, GInitData);

Result := '';

/C route


本文标签: 信息 网关 设置 本机 地址