当前位置:网站首页>MFC获取本机IP(网络通讯时用得多)
MFC获取本机IP(网络通讯时用得多)
2022-04-23 19:24:00 【ToneChip】
CString CUDPDlg::GetIP() //获取本地IP
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255]; // 本地主机名字符数组变量
CString m_ip; // IP地址字符串变量
PHOSTENT hostinfo; // hostent结构指针
wVersionRequested = MAKEWORD(2, 0); //连接应用程序与winsock Dll
if (WSAStartup(wVersionRequested, &wsaData) == 0)
{
if (gethostname(name, sizeof(name)) == 0) //得到本地主机名
{
if ((hostinfo = gethostbyname(name)) != NULL) //得到主机信息
{
m_ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list); //转换得到IP地址
}
else m_ip = "IP检测失败";
}
WSACleanup(); // 中止winsock DLL的使用
}
return m_ip; //返回IP地址字符串
}
调用如下
CString localIP;
localIP = GetIP(); //得到本机IP
SetDlgItemText(IDC_IP1, localIP); //获取到的本机IP显示到界面
版权声明
本文为[ToneChip]所创,转载请带上原文链接,感谢
https://tonechip.blog.csdn.net/article/details/122943159
边栏推荐
- Decompile and get the source code of any wechat applet - just read this (latest)
- [record] typeerror: this getOptions is not a function
- HTTP cache - HTTP authoritative guide Chapter VII
- [记录]TypeError: this.getOptions is not a function
- OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
- 精简CUDA教程——CUDA Driver API
- Codeforces Round #783 (Div. 2) D题解
- goroutine
- Common SQL commands
- Data analysis learning directory
猜你喜欢
网络协议之:sctp流控制传输协议
No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
開關電源設計分享及電源設計技巧圖解
[report] Microsoft: application of deep learning methods in speech enhancement
Virtual machine performance monitoring and fault handling tools
Intuitive understanding of the essence of two-dimensional rotation
FTP, SSH Remote Access and control
[record] typeerror: this getOptions is not a function
Pdf reference learning notes
Use of fluent custom fonts and pictures
随机推荐
Class loading mechanism
First experience of using fluent canvas
Codeforces Round #784 (Div. 4)
点云数据集常用处理
Pit encountered using camera x_ When onpause, the camera is not released, resulting in a black screen when it comes back
How to select the third-party package of golang
Intuitive understanding of the essence of two-dimensional rotation
Oracle配置st_geometry
@Analysis of conditional on Web Application
Convert string to JSON
高层次人才一站式服务平台开发 人才综合服务平台系统
FTP、ssh远程访问及控制
[记录]TypeError: this.getOptions is not a function
ArcMap连接 arcgis server
命令-sudo
Some ideas about time-consuming needs assessment
mysql通过binlog恢复或回滚数据
arcMap 发布切片服务
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
Openlayers 5.0 loading ArcGIS Server slice service