如何得到自己的公网(外网)IP(50分)

  • 主题发起人 主题发起人 linuxping
  • 开始时间 开始时间
L

linuxping

Unregistered / Unconfirmed
GUEST, unregistred user!
千万别说什么 取网站的源码分析啊

我是要delphi 代码 或 实现思路
 
帮你顶。
我再帮你凑点分。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3657680
 
http://www.ip138.com/
 
有合适答案的,可以到
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3657680
再领我的分啊^_^

前提是:
“我是要delphi 代码 或 实现思路 ”
“千万别说什么 取网站的源码分析啊”
 
去找灰鸽子的源码,里面有一段是取IP的
 
睡觉前我想到了

ICMP干什么的?
跟踪路由嘛?

网上一查,真的有啊

代码:

unit uRoutes;


interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdTCPConnection, IdTCPClient,
IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient,
StdCtrls;

type
TRoutes = class(TThread)
private
{ Private declarations }
icmpseq : integer;
findhost: string;
hop: string;
pingtime: integer;
FResult: TStringList;
FPublicResult: TStringList;
IdIcmpClient1: TIdIcmpClient;
FHost:string;
FFound:Boolean;
procedure IdIcmpClient1Reply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
function GetRoutes: TStringList;
public
{ Public declarations }
procedure Execute;override;
constructor Create; reintroduce;
destructor Destroy;override;

property Host:string read FHost write FHost;
property Routes:TStringList read FResult ;
property PublicRoutes:TStringList read GetRoutes ;
end;


implementation

uses IdStack, idGlobal,IdException;

constructor TRoutes.Create;
begin
inherited Create(true);
self.FreeOnTerminate:=true;
//self.OnTerminate:=MyTerminate;
FResult:=TStringList.Create;
FPublicResult:=TStringList.Create;
IdIcmpClient1:=TIdIcmpClient.create(nil);
IdIcmpClient1.OnReply:=IdIcmpClient1Reply;
end;

destructor TRoutes.Destroy;
begin
IdIcmpClient1.free;
FPublicResult.free;
FResult.Free;
inherited;
end;

procedure TRoutes.Execute;
var
i: integer;
ResolvedHost: string;
begin
if isValidIP(FHost) then
ResolvedHost:=FHost
else
ResolvedHost := gStack.WSGetHostByName(FHost);
IdIcmpClient1.ReceiveTimeout := 2000;

icmpseq :=30;
for i := 1 to icmpseq do begin
if findhost <> ResolvedHost then
begin
hop:=inttostr(i);
IdIcmpClient1.Host := FHost;
IdIcmpClient1.TTL:=i;
FFound:=False;
IdIcmpClient1.Ping;

IdIcmpClient1.Host:=findhost;
IdIcmpClient1.TTL:=icmpseq;


if (not FFound) and (findhost <> '0.0.0.0') then
IdIcmpClient1.Ping;


if (not FFound) and (findhost <> '0.0.0.0') then
IdIcmpClient1.Ping
else
continue;


if (not FFound)and (findhost <> '0.0.0.0') then
IdIcmpClient1.Ping;
end;
end;
end;

function TRoutes.GetRoutes: TStringList;
var
I:integer;
begin
FPublicResult.Assign(FResult);
for I:=FPublicResult.Count-1 downto 0 do
begin
if pos('192.168.',FPublicResult)<>0 then //不知道这样是不是公网
FPublicResult.Delete(I);
end;
result:=FPublicResult;
end;

procedure TRoutes.IdIcmpClient1Reply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
begin
findhost:=AReplyStatus.FromIpAddress;
if (AReplyStatus.BytesReceived <> 0 ) and (AReplyStatus.SequenceId <> 0) then
begin
FFound:=true;
FResult.append(findhost);
end;
end;

end.
 
C:/Documents and Settings/Administrator>ipconfig /all

Windows IP Configuration

Host Name . . . . . . . . . . . . : WWxxx
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter 本地连接:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Broadcom NetXtreme Gigabit Ethernet
Physical Address. . . . . . . . . : 00-16-41-10-FB-92
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.11.xx
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.11.1
DNS Servers . . . . . . . . . . . : 202.96.128.86

PPP adapter 宽带连接:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
Physical Address. . . . . . . . . : 00-53-45-00-00-00
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 58.63.66.xx <<<<<<< 外网IP
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 58.63.66.xx
DNS Servers . . . . . . . . . . . : 202.96.128.166
202.96.128.86
NetBIOS over Tcpip. . . . . . . . : Disabled

Ethernet adapter 无线网络连接:

Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : Intel(R) PRO/Wireless 2915ABG Network Connection
Physical Address. . . . . . . . . : 00-12-F0-DE-F1-11
 
留下QQ发一个现成的给你
 
netfun2000_tom.com,请将_换成@
谢谢。
 
fanronghua@126.com
 
我也关心这个问题
也请发一个给我
focus_china@yahoo.com.cn
 
也给我发一份好吗??。。 jmh-521@163.com
 
wangpingdejiejie@163.com
 
能否发一份?谢谢bowang1@163.com
 
没有收到。
 
多人接受答案了。
 
后退
顶部