我的机器在局域网内,我们的局域网通过ADSL连接到Internet,请问应该如何取得我的机器的对外IP呢?
解决方案 »
- 求教:ADOQuery中的大批量数据如何快速保存到SQL Server
- 请教:IdTCPClient通讯过程中,iohandler改变问题
- 怎样让delphi不记住上次在edit、combox等组件中输入或选择的内容;怎样让delphi不记住上次查看的pagecontrol的sheet
- 请问用delphi实现N阶层算法,要求用函数或者过程
- 为什么我的msn message 上不来呢?qq也是如此
- 关于DBGrid的问题!
- delphi的系统分析员请进来。
- 关于多个DataSet使用事务的讨论
- DELPHI中输入问题
- 如何在函数里面传字符串数组
- 在线请教!!!怎样把内存中的图片取出来??
- 关于TreeView为什么不能使用TreeView1.Items.Item[0].Expand(False)来展开第一节
你的本地IP经过NAT上网,对方接受到的是NAT出口IP,也就是你的InternetIP了1)访问你的ADSL或NAT路由器,获得外网IP2)通过访问外部的Web服务获得,HTTP访问Internet的Web服务,它必定知道你的IP,结果下载回来就可以了。你需要外部服务器的支持:)例如http://www.hao123.com/ss/localip.htm
呵呵
PRASConn = ^TRASConn;
TRASConn = record
dwSize: DWORD;
hRasConn: HRASConn;
szEntryName: array[0..RAS_MaxEntryName] of Char;
szDeviceType: array[0..RAS_MaxDeviceType] of Char;
szDeviceName: array[0..RAS_MaxDeviceName] of char;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRASConnStatus = ^TRASConnStatus;
TRASConnStatus = record
dwSize: LongInt;
dwError: LongInt;
rasConnstate: Word;
szDeviceType: array[0..RAS_MaxDeviceType] of Char;
szDeviceName: array[0..RAS_MaxDeviceName] of Char;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRASDIALEXTENSIONS= ^TRASDIALEXTENSIONS;
TRASDIALEXTENSIONS= record
dwSize: DWORD;
dwfOptions: DWORD;
hwndParent: HWND;
reserved: DWORD;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRASDialParams = ^TRASDialParams;
TRASDialParams = record
dwSize: DWORD;
szEntryName: array[0..RAS_MaxEntryName] of Char;
szPhoneNumber: array[0..RAS_MaxPhoneNumber] of Char;
szCallbackNumber: array[0..RAS_MaxCallbackNumber] of Char;
szUsername: array[0..UNLEN] of Char;
szPassword: array[0..PWLEN] of Char;
szDomain: array[0..DNLEN] of Char;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRASEntryName = ^TRASEntryName;
TRASEntryName = record
dwSize: LongInt;
szEntryName: array[0..RAS_MaxEntryName] of Char;
{ Reserved: Byte;}
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TRASPPPIP = record
dwSize: DWORD;
dwError: DWORD;
szlpAddress: array[0..15] of char;
end;//==============================================================================
//取得拨号连接的IP地址**********************************************************
//==============================================================================
procedure GetRasIP(var RasIP: PChar; Index: Byte = 0);
var BufSize, Connxions, RASIPSize: DWORD;
RASPPPIP: TRASPPPIP;
RasConn: array[0..24] of TRasConn;
begin
RasConn[Index].dwSize := SizeOf(TRasConn);
BufSize := SizeOf(TRasConn);
if RasEnumConnections(@RasConn, BufSize, Connxions)=0 then
begin
RASPPPIP.dwsize := SizeOf(TRASPPPIP);
RASIPSize := SizeOf(TRASPPPIP);
RASGetProjectionInfo(RasConn[Index].hRasConn, $8021, RASPPPIP, RASIPSize);
lstrcpy(RasIP, RASPPPIP.szlpAddress);
end;
end;
lpszPhonebook: PChar; { pointer to full path and filename of phonebook file }
lpRasDialParams : PRASDIALPARAMS; { pointer to calling parameters data }
dwNotifierType : DWORD; { specifies type of RasDial event handler }
lpvNotifier: DWORD; { specifies a handler for RasDial events }
var rasConn: HRASConn { pointer to variable to receive connection handle }
): DWORD; stdcall;function RasEnumConnections(RASConn: PrasConn; { buffer to receive Connections data }
var BufSize: DWord; { size in bytes of buffer }
var Connections: DWord { number of Connections written to buffer }
): LongInt; stdcall;function RasEnumEntries(reserved: PChar; { reserved, must be NULL }
lpszPhonebook: PChar ; { pointer to full path and filename of phonebook file }
lprasentryname: PRASENTRYNAME ; { buffer to receive phonebook entries }
var lpcb: DWORD; { size in bytes of buffer }
var lpcEntries : DWORD { number of entries written to buffer }
): DWORD; stdcall;function RasGetConnectStatus(RASConn: hrasConn; { handle to Remote Access Connection of interest }
RASConnStatus: PRASConnStatus { buffer to receive status data }
): LongInt; stdcall;function RasGetErrorString(ErrorCode: DWord; { error code to get string for }
szErrorString: PChar; { buffer to hold error string }
BufSize: DWord { sizeof buffer }
): LongInt; stdcall;function RasHangUp(RASConn: hrasConn { handle to the Remote Access Connection to hang up }
): LongInt; stdcall;function RasGetEntryDialParams(lpszPhonebook:PChar; { pointer to the full path and filename of the phonebook file }
var lprasdialparams:TRASDIALPARAMS; { pointer to a structure that receives the connection parameters }
var lpfPassword : BOOL { indicates whether the user's password was retrieved }
): DWORD; stdcall;function RASGetProjectionInfo(hRasConn: THandle;
RasProjection: DWORD;
var lpRasPPPIP: TRasPPPIP;
var lpcb: DWORD
): DWORD; stdcall;const RASAPI32 = 'RASAPI32.DLL';function RasDial; external RASAPI32 name 'RasDialA';
function RasHangUp; external RASAPI32 name 'RasHangUpA';
function RasEnumEntries; external RASAPI32 name 'RasEnumEntriesA';
function RasGetErrorString; external RASAPI32 name 'RasGetErrorStringA';
function RasEnumConnections; external RASAPI32 name 'RasEnumConnectionsA';
function RasGetConnectStatus; external RASAPI32 name 'RasGetConnectStatusA';
function RASGetProjectionInfo; external RASAPI32 name 'RasGetProjectionInfoA';
function RasGetEntryDialParams; external RASAPI32 name 'RasGetEntryDialParamsA';
Function Tmain_form.GetLocalIp(InternetIP:boolean):String;
type
TaPInAddr = Array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: Array[0..63] of Char;
I: Integer;
GInitData: TWSAData;
IP: String;
begin
Screen.Cursor := crHourGlass;
try
WSAStartup($101, GInitData);
IP:='0.0.0.0';
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then
begin
ShowMessage(IP);
Result:=IP;
Exit;
end;
pPtr := PaPInAddr(phe^.h_addr_list);
if InternetIP then
begin
I := 0;
while pPtr^[I] <> nil do
begin
IP := inet_ntoa(pptr^[I]^);
Inc(I);
end;
end
else
IP := inet_ntoa(pptr^[0]^);
WSACleanup;
Result:=IP;//如果上网则为上网ip否则是网卡ip
finally
Screen.Cursor := crDefault;
end;
end;
-------------------------------------------
在asp 编程里有个函数,具体忘了,你可以找找。