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组件

相关阅读 >>

Delphi 获取文件夹时间

Delphi 判断文本文件的编码格式

Delphi unicode转汉字 ,支持自动过滤非 unicode编码

Delphi 获取本地网络连接

Delphi base64, quoted-printable 的解码与编码函数

Delphi memo 字符串换行

firemonkey下使用stylebook的一些经验

Delphi 安卓获得设备 id

Delphi 随机指定范围的字符串函数

Delphi 在windows平台下实现进程隐藏

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...