获得及设置本机的ip地址,子网掩码,网关,dns服务器信息(Delphi)
获得及设置本机的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 TForm1.Button1Click(Sender:TObject);
begin
Memo1.Lines.Clear;
if FileExists(Temp) then
DeleteFile(Temp);
WinExec(PChar('command /C route print >'+Temp),SW_HIDE);
while not FileExists(Temp) do
Sleep(1000)
Try
Memo1.Lines.LoadFromFile(Temp);
except
end;
end;
3、所有信息
function LocalIP:string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;走a
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;
program get_ip;
uses
winsock,sysutils;
VAR
ch : ARRAY[1..32] OF Char;
i : Integer;
WSData: TWSAData;
MyHost: PHostEnt;
花好月圆 歌词
begin
IF WSAstartup(2,wsdata)<>0 THEN
BEGIN
Writeln('can''t start Winsock: Error ',WSAGetLastError);
Halt(2);
END;
try
IF getHostName(@ch[1],32)<>0 THEN
BEGIN
Writeln('getHostName failed');
Halt(3);
END;
except
Writeln('getHostName failed');
halt(3);
end;
MyHost:=GetHostByName(@ch[1]);
IF MyHost=NIL THEN
BEGIN
Writeln(GetHostName('+StrPas(@ch[1])+') failed : Error
'+IntToStr(WSAGetLastError));
Halt(4);
END
ELSE
BEGIN
Write('address ');
FOR i:=1 TO 4 DO
BEGIN
Write(Ord(MyHost.h_addr^[i-1]));
IF i<4 THEN
then write('.')
ELSE
writeln;
END;
END;
end.
4、获取路由、网关信息、网卡信息:
Procedure TForm1.Button1Click(Sender:TObject);
begin
Memo1.Lines.Clear;
if FileExists(Temp) then
DeleteFile(Temp);
拦截广告WinExec(PChar('command /C route print >'+Temp),SW_HIDE);
while not FileExists(Temp) do
Sleep(1000)
我在男高当校草Try
Memo1.Lines.LoadFromFile(Temp);
except
end;
end;
返利网是如何返利的
5、MAC代码:
procedure TForm1.Button1Click(Sender: TObject);
Var
NCB : TNCB;
ADAPTER : TADAPTERSTATUS;
LANAENUM : TLANAENUM;
intIdx : Integer;
re : Char;
buf : String;
begin
Try
{ ZeroMemory(@NCB, SizeOf(NCB));
b_command := Chr(NCBENUM);
re := NetBios(@NCB);
// Reissue enum command
b_buffer := @LANAENUM;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。