手机
当前位置:查字典教程网 >编程开发 >C语言 >vc获取计算机名和ip地址的方法
vc获取计算机名和ip地址的方法
摘要:本文实例讲述了vc获取计算机名和ip地址的方法。分享给大家供大家参考。具体实现方法如下:#include#include#pragmacom...

本文实例讲述了vc获取计算机名和ip地址的方法。分享给大家供大家参考。具体实现方法如下:

#include <winsock2.h> #include <stdio.h> #pragma comment(lib,"ws2_32.lib") void main() { WSADATA wsadata; WORD dwVersionRequested; int err; err=WSAStartup(dwVersionRequested,&wsadata); char hostname[128]; if(gethostname(hostname,128)==0) { printf("%sn",hostname);//计算机名字 } char buf[20]; //memset(buf,0,80); struct hostent *pHost = gethostbyname(hostname); for (int i = 0; pHost != NULL && pHost->h_addr_list[i] != NULL; i++) { //将它放入字符数组中便于应用 strcpy(buf,inet_ntoa(*(struct in_addr *)pHost->h_addr_list[i])); //inet_ntoa(*(struct in_addr *)pHost->h_addr_list[i]); //IP地址 printf("%sn",buf); } WSACleanup(); }

希望本文所述对大家的VC程序设计有所帮助。

【vc获取计算机名和ip地址的方法】相关文章:

判断机器大小端的两种实现方法

数组中求第K大数的实现方法

数据结构课程设计-用栈实现表达式求值的方法详解

VC WinExec打开指定程序或者文件的方法

atoi和itoa函数的实现方法

深入全排列算法及其实现方法

用c 获取文件MD5值的实现方法

随机数字去掉重复和排序的方法

linux c 获取本机公网IP的实现方法

解决C++中重定义的方法总结

精品推荐
分类导航