请教!如何编程序得到本机拨号上网的ip地址(本机在局域网内,有一个ip地址,不是这个)

CKEN 2000-03-28 05:57:00
如题
...全文
132 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Un1 2000-04-07
  • 打赏
  • 举报
回复
Dim lpraspppip As RASPPPIP
lpraspppip.dwSize = 40
If RasGetProjectionInfo(mhConn, RASP_PppIp, lpraspppip, 40) = 0 Then
mRemoteIPAddress = TrimNull(StrConv(lpraspppip.szServerAddress, vbUnicode))
End If
honeyhu 2000-04-06
  • 打赏
  • 举报
回复
通过拨号用 PPP 上网,本身有网卡 NIC。在求 ip 地址时总是只得到一个 ip(实际是NIC
的 IP),无法得到另一个 ip。最近再试了一下,可以得到两个 ip。
代码为:
char szHostName[128];
CString m_IpAdd1, m_IpAdd2;
if( gethostname(szHostName, 128) == 0 ) //得到本地机名
{
struct hostent * pHost;
pHost = gethostbyname(szHostName);
m_IpAdd1 = inet_ntoa(*((struct in_addr*)(pHost->h_addr_list[0])));
//第一个 ip,为 NIC IP
if (pHost->h_addr_list[1] != NULL) //没有拨号时当然没有PPP IP
m_IpAdd2 = inet_ntoa(*((struct in_addr*)(pHost->h_addr_list[1])));
//第二个 ip,为 PPP IP
}
kxy 2000-03-28
  • 打赏
  • 举报
回复
procedure TForm1.ButtonIPClick(Sender: TObject);
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);
Exit;
end;
pPtr := PaPInAddr(phe^.h_addr_list);
I := 0;
while pPtr^[I] <> nil do
begin
IP := inet_ntoa(pptr^[I]^);
Inc(I);
end;
WSACleanup;
ShowMessage(IP);
finally
Screen.Cursor := crDefault;
end;
end;

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧