怎样用程序得到我的公网ip用本地ip

解决方案 »

  1.   

    uses IdStack;
    procedure getcomputerip(outdata:Tstrings);
    var
      AIdStack:TIdStack;
    begin
     AIdStack:=TIdStack.CreateStack;
     try
     outdata.Text:=AIdStack.LocalAddresses.Text;//获取本地IP地址列表
     finally
     AIdStack.free;
     end;
    end;
      

  2.   

    公网IP呢,本地IP用delphi7控件都可以,但公网IP呢。
      

  3.   

    你试试看RAS_MaxDeviceType = 16; //设备类型名称长度
     RAS_MaxEntryName = 256; //连接名称最大长度
     RAS_MaxDeviceName = 128; //设备名称最大长度
     RAS_MaxIpAddress = 15; //IP地址的最大长度
     RASP_PppIp = $8021; //拨号连接的协议类型,该数值表示PPP连接type
     HRASCONN = Cardinal; //拨号连接句柄的类型
     RASCONN = record //活动的拨号连接的句柄和设置信息
       dwSize: Cardinal; //该结构所占内存的大小(Bytes), 一般设置为SizeOf(RASCONN)
       hrasconn: HRASCONN; //活动连接的句柄
       szEntryName: array[0..RAS_MaxEntryName] of char; //活动连接的名称
       szDeviceType: array[0..RAS_MaxDeviceType] of char; //活动连接的所用的设备类型
       szDeviceName: array[0..RAS_MaxDeviceName] of char; //活动连接的所用的设备名称
     end; TRASPPPIP = record //活动的拨号连接的动态IP地址信息
       dwSize: Cardinal; //该结构所占内存的大小(Bytes),  一般设置为SizeOf(TRASPPPIP)
       dwError: Cardinal; //错误类型标识符
       szIpAddress: array[0..RAS_MaxIpAddress] of char; //活动的拨号连接的IP地址
     end;
    获取Local IPfunction GetLocalIP(HostName: PChar; IPAddress: PChar): boolean; stdcall;
    var
     ch: array[0..32] of Char;
     WSData: TWSAData;
     MyHost: PHostEnt;
    begin
     result := false;
     try
       if WSAstartup(2, wsdata) <> 0 then
         exit;
       if getHostName(ch, sizeof(ch)) <> 0 then
         exit;
       MyHost := GetHostByName(ch);
       if MyHost = nil then
         exit;
       strCopy(HostName, MyHost.h_name);
       strPCopy(IPAddress, format('%d.%d.%d.%d',
         [byte(MyHost.h_addr^[0]), byte(MyHost.h_addr^[1]),
         byte(MyHost.h_addr^[2]), byte(MyHost.h_addr^[3])]));
       result := true;
     finally
       WSACleanUp;
     end;
    end;获取你上网时在线上的动态IP地址function GetRASIP(IPAddress: PChar): boolean; stdcall;
    const
     MaxConnections = 10; //假设最多有10个活动的拨号连接
    var
     connections: array[0..MaxConnections - 1] of RASCONN;
     //拨号连接数组
     longSize: Cardinal;
     intAvailableConnections: Cardinal;
     //活动的拨号连接的实际数目
     intIndex: integer;
     strTemp: string;
     dwResult: Cardinal;
     dwSize: Cardinal;
     RASpppIP: TRASPPPIP;
     //活动的拨号连接的动态IP地址信息
    begin
     result := false;
     connections[0].dwSize := sizeof(RASCONN);
     longSize := MaxConnections * connections[0].dwSize;
     //接收活动连接的缓冲区大小
     intAvailableConnections := 0;
     //获取所有活动的拨号连接的信息(连接句柄和设置信息)
     if RasEnumConnections(connections[0], longSize, intAvailableConnections) <> 0
       then
       exit;
     if intAvailAbleConnections = 0 then
       exit;
     dwSize := sizeof(RASpppIP);
     RASpppIP.dwSize := dwSize;
     if RASGetProjectionInfo(Connections[0].hrasconn, RASP_PPPIP, RaspppIP, dwSize)
       <> 0 then
       exit;
     strCopy(IPAddress, RASpppIP.szIpAddress);
     result := true; {  for intIndex := 0 to intAvailabelConnections - 1 do
       begin
           //显示一个活动的拨号连接的设置信息
           strTemp := '连接名称:'
             + StrPAS(connections[intIndex].szEntryName)
             + ',设备类型:'
             + StrPAS(connections[intIndex].szDeviceType)
             + ',设备名称:'
             + StrPAS(connections[intIndex].szDeviceName);
           memo1.lines.add(strTemp);
           //显示一个活动的拨号连接的动态IP地址
           dwSize := SizeOf(RASpppIP);
           RASpppIP.dwSize := dwSize;
           dwResult := RASGetProjectionInfo
             (connections[intIndex].hRasConn,
             RASP_PppIp, RasPPPIP, dwSize); //获取动态IP地址
           if 0 < > dwResult then
             memo1.lines.add(
               '错误:' + inttostr(dwResult))
           else
             memo1.lines.add(
               '动态地址:' + StrPas(RASpppIP.szIPAddress));
         end;
       end;}
    end;
      

  4.   

    RasEnumConnections在哪个单元里呀,我的机子上找不见rasapi.pas文件。
      

  5.   

    getit911(Windows转Linux中)是最简单的方法了!你不会是在局域网内想得到出口的IP吧?
      

  6.   

    哪里有这个函数,
    我用delphi的
      

  7.   

    在局域网内像通过ADSL上网公网IP都是不固定,不是很多论坛的页面都可以得到你的IP吗,参考一下他们的代码,通过发送这种网页请求,再对取得的结果进行分析就可以了吧!这只是一个建议,具体怎么做还没试过。
      

  8.   

    我也想知道....
    局域网的IP用一个IDIPWATCH控件就可以得到
      

  9.   

    我也是用delphi+asp实现的www.eastrise.cn/ip.asp看看这个.....然后再用delphi来取数据...
      

  10.   

    To:jackie168(花好月圓)
    那我在delphi中取得ip时,每次都要打开一个web网页吗?如果我没有安装iis呢, 还可以吗。
    不知你怎么实现的。不过可以在delphi中加入asp代码。不知能不能实现
      

  11.   

    下面给出我的原文件:
    ===================================================
    unit UnitIP;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
      IdHTTP, XPMan, StdCtrls, Buttons, ExtCtrls,WinInet;  {========================================================================
      DESIGN BY :  花好月圆 / 玉面书生
      DATE:        2005-01-27
      SITE:        http://www.eastrise.cn/quick2004
      BLOG:        http://blog.csdn.net/jackie168
      EMAIL:       [email protected]  文章为作者原创,转载前请先与本人联系,转载请注明文章出处、保留作者信息,谢谢支持!
    =========================================================================}
    type
      TForm1 = class(TForm)
        Panel1: TPanel;
        BitBtn1: TBitBtn;
        XPManifest1: TXPManifest;
        IdHTTP1: TIdHTTP;
        procedure BitBtn1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    function ExtractStr(Str: string): string;  //格式字符串
    var i,j:integer;
    begin
      Result:='';
    j:=Length(str);
    for i:=0 to j do
    begin
    if str[i] in ['0'..'9','.'] then
    Result:=Result+str[i];
    end;
    end;function  IsInternet:  Boolean; //检查是否连上网络
    begin  
       if  InternetCheckConnection('http://www.eastrise.cn/ip.asp',  1,  0)  then
           Result  :=  True  
       else  
           Result  :=  False;  
    end;procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
        if IsInternet then
        begin
        Panel1.Caption:='你的公网IP:'+
        ExtractStr(IdHTTP1.Get('http://www.eastrise.cn/ip.asp'));  //取IP地址
        end
        else
        application.MessageBox('该机器未连接网络或服务器出错!','错误',mb_ok+mb_iconerror);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      panel1.Caption:=''; //初始化
    end;end.
      

  12.   

    'http://www.eastrise.cn/ip.asp'
    如果没有这个怎么做啊?有没方法?
      

  13.   

    怎么得到某个域名的IP地址:
    比如www.baidu.com.怎么在程序中得到PING到的地址/
      

  14.   

    以下是我用的ASP代码,大家参考一下:
    <html>
    <%
    cip=Request.ServerVariables("REMOTE_ADDR")
    %>
    <body>
    cip=<%=cip%>
    </body>
    </html>
      

  15.   

    用ASP取客户端IP是很简单,但是不通过ASP网页怎样达到楼主的要求呢?有没有哪位有方法?
      

  16.   

    xiaochensu(拒绝水的鱼)
    返回结果是:cip=
      

  17.   

    asp.net的我知道
    通过dns类可以实现,asp的要怎么实现呀.
      

  18.   

    xiaochensu(拒绝水的鱼)怎么不行的.
      

  19.   

    用asp有问题,假如用了代理,看到的就是代理的地址了。从网络结构上考虑:经过网关时数据被打包,返回时被解包,始终看不到网关的公网地址。似乎没有好的方法。
      

  20.   

    http://www.linxin.net/Article_Show.asp?ArticleID=13