当前位置:网站首页>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
边栏推荐
- Kubernetes入门到精通-KtConnect(全称Kubernetes Toolkit Connect)是一款基于Kubernetes环境用于提高本地测试联调效率的小工具。
- 开关电源设计分享及电源设计技巧图解
- All table queries and comment description queries of SQL Server
- Openlayers 5.0 discrete aggregation points
- 优先使用组合而不使用继承
- [record] typeerror: this getOptions is not a function
- Zero cost, zero foundation, build profitable film and television applet
- Core concepts of rest
- 精简CUDA教程——CUDA Driver API
- OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
猜你喜欢
arcMap 发布切片服务
2021-2022-2 ACM集训队每周程序设计竞赛(8)题解
[报告] Microsoft :Application of deep learning methods in speech enhancement
精简CUDA教程——CUDA Driver API
An idea of rendering pipeline based on FBO
OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
I just want to leave a note for myself
Oracle configuration st_ geometry
MySQL syntax collation (5) -- functions, stored procedures and triggers
[transfer] summary of new features of js-es6 (one picture)
随机推荐
arcgis js api dojoConfig配置
Golang timer
The flyer realizes page Jump through routing routes
goroutine
Codeforces Round #783 (Div. 2) D题解
arcMap 发布切片服务
The platinum library cannot search the debug process records of some projection devices
Core concepts of rest
開關電源設計分享及電源設計技巧圖解
PostgreSQL
命令-sudo
Go modules daily use
Easy mock local deployment (you need to experience three times in a crowded time. Li Zao will do the same as me. Love is like a festival mock)
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
[play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
Virtual machine performance monitoring and fault handling tools
[报告] Microsoft :Application of deep learning methods in speech enhancement
SSDB foundation 1
Openlayers 5.0 discrete aggregation points
Summary of several relationships of UML class diagram