取外网IP函数

来源:互联网 发布:怎么查看windows密码 编辑:程序博客网 时间:2024/06/05 19:13
注:取自群友的函数
function GetWanIp: string;
var
   xml : OleVariant;
   r:string;
   p1,p2 : Integer;
begin
   xml := CreateOleObject('Microsoft.XMLHTTP');
   xml.Open('GET','http://www.net.cn/static/customercare/yourIP.asp', False);
   xml.Send;
   r := xml.responseText;
   p1:=Pos('<h2>',r); // 找到 h2 标签
   p2:=Pos('</h2>',r);   // 找到 h2 结束标签
   Result := Copy(r, p1+4, p2-p1-4);
end;
另一法,通过uPnP协议,在内网直接从路由器里取
使用TBurroNAT控件的GetExternalIP方法
原创粉丝点击