我想知道如何去得到:
内部IP地址;
外部IP地址; 和
默认网关
在Windows(WinSock)和Unix系统中。
提前致谢,
为什么我的Linux prio基于tc没有改善networking延迟?
如何在浏览器中打开HTML文件在centos?
SNOS中的SNAT目标选项
如何通过Java获得Linux上的计算机的IP?
Linux中的netstat -s给出的意思是什么意思
如何拦截在Linux上的IP数据包
更改udp服务器的默认源IP与INADDR_ANY绑定
外部http连接失败(端口打开)
PHP中的REMOTE_ADDR和IPv6
在Windows和UNIX上没有通用的机制。 在Windows下,你想从GetIfTable()开始。 在大多数UNIX系统下,尝试getifaddrs() 。 这些将给你各种各样的东西,如每个接口的IP地址。
我不知道如何获得默认网关。 我猜可以通过调用sysctl 。 您可能需要从netstat实用程序的源代码开始。
外部公共地址是电脑从来不知道的东西。 唯一的办法是连接到互联网上的东西,并告诉你你来自哪个地址。 这是IPNAT的经典问题之一。
解决了感谢: http : //www.codeguru.com/forum/showthread.PHP? t=233261
#include <winsock2.h> #include <stdio.h> #include <stdlib.h> #pragma comment(lib,"ws2_32.lib") int main(int nArgumentCount,char **ppArguments) { WSADATA WSAData; // Initialize WinSock DLL if(WSAStartup(MAKEWORD(1,0),&WSAData)) { // Error handling } // Get local host name char szHostName[128] = ""; if(gethostname(szHostName,sizeof(szHostName))) { // Error handling -> call 'WSAGetLastError()' } SOCKADDR_IN socketAddress; hostent *pHost = 0; // Try to get the host ent pHost = gethostbyname(szHostName); if(!pHost) { // Error handling -> call 'WSAGetLastError()' } char ppszIPAddresses[10][16]; // maximum of ten IP addresses for(int iCnt = 0; (pHost->h_addr_list[iCnt]) && (iCnt < 10); ++iCnt) { memcpy(&socketAddress.sin_addr,pHost->h_addr_list[iCnt],pHost->h_length); strcpy(ppszIPAddresses[iCnt],inet_ntoa(socketAddress.sin_addr)); printf("Found interface address: %sn",ppszIPAddresses[iCnt]); } // Cleanup WSACleanup(); }
Linux的:
ifconfig -a gives internal ip netstat -a gives default gateway
视窗:
ipconfig /all gives internal ip netstat -a gives default gateway
我不知道如何确定任何一个系统的外部IP
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。