举两个例子:(1)主机上同时装有网卡和 Modem,网卡设置了 IP 地址连接内网,Modem 已经拨号并连通了 Internet,如何得到此时可用 Internet 连接的 IP,而不是网卡的 IP?(2)主机上装了一块网卡,网卡设置了 192.168.0.23 的 IP 用于连接内网,然后通过网通拨号程序拨号连通 Internet,此时网卡又有了一个合法外部 IP,如何得到此时可用 Internet 连接的 IP,而不是网卡用来连接居域网的 IP?我想大概这两种情况用的解决方法(API)是一样的,但是不知道如何得到,请大家帮忙,解决后马上给分!
http://www.csdn.net/expert/topic/881/881170.xml?temp=.3162348
http://www.vckbase.com/document/viewdoc.asp?id=435这种方法跟你说的那种方法效果一样吗?另外能给我发一份 Iphlpapi.h 和 Iphlpapi.lib 吗?[email protected],谢谢!
如在(1)中就应该返回modem的IP,而不是网卡的IP。
这个行吗?
我还见过一个用SNMP的方法,但是现在找不到,晚上回家找找。
http://www.vckbase.com/document/viewdoc.asp?id=435
上说的方法得到的全部是本地地址wuxuan(真心英雄) 给出的
http://www.csdn.net/expert/topic/881/881170.xml?temp=.3162348
因为我缺少两个文件所以没办法试哪位好心人给我发一下啊?[email protected]
WinPCap用来写这个还不算过分
就可以知道的,你的机器的作client,别人的作server,建立socket后,server是肯定知道client的IP的,不过server的IP还是的知道先,否则没法socket。呵呵,这个办法,好像不好
void CMyView::OnToolsViewip() {
struct hostent * pHostent=NULL;
CString strIP, strTemp("");
char addr[256]; gethostname(addr,255);
pHostent=gethostbyname(addr);
if(pHostent!=NULL && pHostent->h_addr_list[0]!= NULL){
int i=0;
strIP.Format("本机IP地址为:\n\n");
while(pHostent->h_addr_list[i]!= NULL){
strIP += "";
for(int j=0; j < pHostent->h_length; j++ ){
if( j > 0 ) strIP += ".";
strTemp.Format("%u", (UINT)((unsigned char*)pHostent->h_addr_list[i])[j]);
strIP += strTemp;
}
i++;
strIP += "\n";
}
}
AfxMessageBox(strIP);
}不过我不知道怎样才可以知道哪个才是当前的连接IP。