如何得到本地机的网关,子网掩码,急用,在线等待!(20分)

  • 主题发起人 protagonist
  • 开始时间
P

protagonist

Unregistered / Unconfirmed
GUEST, unregistred user!
如何得到本地机的网关,子网掩码,急用,在线等待!
 
查查注册表。
 
控制台命令:ipconfig
 
是要用DELPHI写个函数得到网关和子网掩码。
 
ipconfig/all
 
有没有此类的API函数。
 
用delphi查注册表不就行了吗?
 
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/{88C2BAB9-793F-4634-9C52-B0D8EAC0ACCC}/Parameters/Tcpip
或者
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/Tcpip/Parameters/Interfaces/{88C2BAB9-793F-4634-9C52-B0D8EAC0ACCC}
你要的所有信息都在这里边。你用delphi写个程序读注册表就可以了!
 
如果有多个网卡呢?
难道没有API吗?
 
//-------取得電腦IP Address----------------------------------------
function ComputerIP:String;
var phe:pHostEnt;
w:TWSAData;
ip_address:longint;
p:^longint;
ipstr:string;
begin
if WSAStartup(2,w)<>0 then exit;
phe:=gethostbyname(pchar(ComputerName));
if phe<>nil then
begin
p:=pointer(phe^.h_addr_list^);
ip_address:=p^;
ip_address:=ntohl(ip_address);
ipstr:=IntToStr(ip_address shr 24)+'.'+IntToStr((ip_address shr 16) and $ff)
+'.'+IntToStr((ip_address shr 8) and $ff)+'.'+IntToStr(ip_address and $ff);
Result :=ipstr;
end;
end;
 
如果一台机器有两个ip
能取出来么?
 
取本机所有IP(可以有多个):

uses WinSock;

procedure TForm1.Button1Click(Sender: TObject);
type
TaPInAddr = Array[0..20] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
pptr: PaPInAddr;
Buffer: Array[0..63] of Char;
i: integer;
begin

WSAStartup(2, WSAData);
GetHostName(Buffer, SizeOf(Buffer));
HostEnt := GetHostByName(buffer);
if HostEnt <> nil then
begin
pPtr := PaPInAddr(HostEnt^.h_addr_list);
i := 0;
while (pPtr^ <> nil) and (i<20) do
begin
ListBox1.Items.Add(inet_ntoa(pptr^^));
Inc(i);
end;
end;
WSACleanup;

end;
 
to zw84611
你有没有方法取得网关呀,能适用与9X和2000下。
 
一定要这样才算完事吗。
procedure GetGateWay;
var
reg:tregistry;
begin
Reg := TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
reg.OpenKey('/System/CurrentControlSet/Services/Class/NetTrans/0000',true);
showmessage(reg.ReadString('DefaultGateway'));
end;

大家能不能想想还有别的办法吗。
 
用IPHelpAPI可以得到整个路由表
http://www.playicq.com/dispdoc.php?t=27&amp;id=1575
 
参见 http://www.delphibbs.com/delphibbs/dispq.asp?lid=958339
 
用adkiller6。0,还不错
 
多人接受答案了。
 
顶部