delphi 获取外网IP的函数


获取外网IP的函数
function GetIP: string;
var
r: string;
p1, p2: Integer;
begin
r := idhttp1.get('http://www.net.cn/static/customercare/yourIP.asp');
p1 := Pos('<h2>', r); // 找到 h2 标签
p2 := Pos('</h2>', r); // 找到 h2 结束标签
Result := Copy(r, p1 + 4, p2 - p1 - 4);
end;
/////////////获取内网IP
function GetLocalIP: 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;


Indy9里面的HTTP组件
联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678