用ADSL上网后,如何用代码取得因特网IP是多少?(5分)

  • 主题发起人 主题发起人 kingbenz
  • 开始时间 开始时间
K

kingbenz

Unregistered / Unconfirmed
GUEST, unregistred user!
用ADSL上网后,如何用代码取得因特网IP是多少?
 
只是通过ADSL上网,很容易就能得到IP;但如果是用上了ADSL的路由功能的话,暂时无解。
 
来自:c3411080, 时间:2003-12-29 13:49:00, ID:2381605
//可以获得在局域网里的IP以及internet中的IP
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,winsock,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
type
//copy the add_list
TAddrList = array [0..20] of PInAddr;
PAddrList = ^TAddrList;
var
phent : PHostEnt;
P: PAddrList;
I : Integer;
begin
{ CopyRight (C) Bowman 2000 }
{ MatthewBowman@21cn.com }
//detect yahoo.com
phent := GetHostByName(pchar(edit1.text));
if phent<>nil then
begin
I := 0;
P := PAddrList(phent^.h_Addr_list);
while P <> nil do
begin
listbox1.items.Add(StrPas(inet_ntoa(P^)));
Inc(I)
end
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
WSAData : TWSAData;
begin
//initiates use of WS2_32.DLL
if (WSAStartup(MAKEWORD(2,0),WSAData)<>0) then
raise Exception.Create('Winsock Version Error');
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
WSACleanUP;
end;

end.
 
不是太明白你想問什麽?如果是你自己用ADSL上網,上網後想知道自己的IP地址,那好像跟你是不是ADSL上網沒多大關係吧!
 
接受答案了.
 
后退
顶部