打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
delphi 获得外网IP的

delphi 获得外网IP的

时间:2011-5-30来源:yang 作者: peng点击: 61次

获得外网IP的函数,方法有点笨,请高手指正。

use IdHTTP;

function GetIP:string;
const
  p1 = ‘_blank‘;
  p2 = ‘direction=left width=>‘;
  Http1 = ‘http://code.helpor.net/mine/ip.php‘;
  Http2 = ‘http://ip.91.com/ip/showip.asp‘;
var
  s:string;

  function GetHttp(sHttp:string):string;
  var
    IdHTTP1:TIdHTTP;
  begin
    try
      IdHTTP1 := TIdHTTP.Create(nil);
      try
        Result := IdHTTP1.Get(sHttp);
      finally
        IdHTTP1.Free;
      end;
    except

    end;
  end;
begin
  Result := ‘获取IP失败‘;
  s := GetHttp(Http1);
  if (s <> ‘‘) and (pos(p1, s) > 0) then
  begin
    s := MidBStr(s, pos(p1, s) + length(p1) + 2, 17);
    s := MidBStr(s, 1, pos(‘<‘, s)-1);
    Result := s;
  end
  else begin
    s := GetHttp(Http2);
    if pos(p2, s) <= 0 then exit;
    s := MidbStr(s, pos(p2, s) + length(p2), 15);
    s := MidBStr(s, 1, pos(‘ ‘, s)-1);
    Result := s;
  end;
end;

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Delphi获取内外网IP
Delphi编程中Http协议应用(一)
Delphi的idhttp报IOHandler value is not valid错误的原因
Delphi的IDHTTP的基本用法
delphi 获取网络文件大小
使用IDHTTP登录网站
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服