请问怎么可以获得局域网电脑的外部IP! (50分)

  • 主题发起人 主题发起人 aipingren
  • 开始时间 开始时间
A

aipingren

Unregistered / Unconfirmed
GUEST, unregistred user!
我装的是小区光纤宽贷,有两个IP(一个是自己设置的内部IP,还有个是上网通讯的外部IP)!用网上的获得本机IP的例子获得的都是内部的IP!请问怎么
才可以得到外部IP!(在ms-dos下用ipconfig 就可以看到这个两个IP,但我想用编程方法得到,怎么办?)
 
UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPU
UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPU
UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPU
UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPU
UPUPUPUPUPUPUPUPUPUPUPUPUPUPUP
UPUPUPUPUPUPUPUPUPUPU
UPUPUPUPUPUPUPUP
UPUPUPUPUPUP
UPUPUPUP
UPUPUP
UPUP
UP
 
下面的ASP文件可以做得到。

<html>
<body>
<TABLE BORDER="1">
<TR><TD><B>Server Variable</B></TD><TD><B>Value</B></TD></TR>
<% For Each strKey In Request.ServerVariables %>
<TR><TD> <%= strKey %> </TD><TD> <%= Request.ServerVariables(strKey) %> </TD></TR>
<% Next %>
</TABLE>
</body>
</html>
 
谁告诉我!再加100分!
 
给个函数
//获取本机IP地址
//InternetIP=True 获得外网IP地址,你要求的
//InternetIP=FALSE 获得内网IP地址,本机
Function GetLocalIp(InternetIP:boolean):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;
IP: String;
begin
Screen.Cursor := crHourGlass;
try
WSAStartup($101, GInitData);
IP:='0.0.0.0';
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then
begin
ShowMessage(IP);
Result:=IP;
Exit;
end;
pPtr := PaPInAddr(phe^.h_addr_list);
if InternetIP then
begin
I := 0;
while pPtr^ <> nil do
begin
IP := inet_ntoa(pptr^^);
Inc(I);
end;
end
else
IP := inet_ntoa(pptr^[0]^);
WSACleanup;
Result:=IP;//如果上网则为上网ip否则是网卡ip
finally
Screen.Cursor := crDefault;
end;
end;

 
ipconfig -all
 
多人接受答案了。
 
后退
顶部