可以用下面的代码根据计算机名称得到IP地址:
void print_all_ip(void)
{
char szHostName[128];
const char* pszAddr;
struct hostent * pHost;
int i,j;
if( gethostname(szHostName, 128) == 0 )
{
pHost = gethostbyname(szHostName);
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{/*对每一个IP地址进行处理*/
pszAddr=inet_ntoa (*(struct in_addr *)pHost->h_addr_list[i]);
printf("%s\n",pszAddr);/*打印*/
}
}
}
void print_all_ip(void)
{
char szHostName[128];
const char* pszAddr;
struct hostent * pHost;
int i,j;
if( gethostname(szHostName, 128) == 0 )
{
pHost = gethostbyname(szHostName);
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{/*对每一个IP地址进行处理*/
pszAddr=inet_ntoa (*(struct in_addr *)pHost->h_addr_list[i]);
printf("%s\n",pszAddr);/*打印*/
}
}
}
解决方案 »
- 实时数据传输采用UDP好还是TCP好?
- VS2005 急急~在项目被建立后 如何能设置回自动化?
- 请教一个实现橡皮擦功能的好的方法
- 请问 汉字 在MHT文件中的编码是什么?
- 谁知道LabWindows/CVI的资料哪里下载呀??
- 清高人帮忙!如图http://www.PicDisk.net/guest/uppics/20060213/3.bmp
- 如何把数据按HEX文件格式写入到.hex文件中?
- 菜题:什么是LCC我不知道,什么是SDK高手指点一二
- 请问学习VC++必须要学习SDK编程吗,怎么学呢?MFC又怎么样呢?
- 求最佳算法
- 试图用键盘钩子来屏蔽全局所有按键, 可是输入法的按键还是有效, 请高手指教一二
- 能不能将*.bmp转化成*.ico格式?
而局域网中另外一台计算机为:211.154.103.84