当前位置:网站首页>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
边栏推荐
- [record] typeerror: this getOptions is not a function
- MySQL syntax collation (4)
- Transaction processing of SQL Server database
- Codeworks round 783 (Div. 2) d problem solution
- RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
- Openlayers 5.0 loading ArcGIS Server slice service
- arcMap 发布切片服务
- Parsing headless jsonarray arrays
- Why is PostgreSQL about to surpass SQL Server?
- 视频理解-Video Understanding
猜你喜欢

The platinum library cannot search the debug process records of some projection devices

mysql通过binlog恢复或回滚数据

No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)

2021-2022-2 ACM集训队每周程序设计竞赛(8)题解
![[report] Microsoft: application of deep learning methods in speech enhancement](/img/29/2d2addd826359fdb0920e06ebedd29.png)
[report] Microsoft: application of deep learning methods in speech enhancement
![[记录]TypeError: this.getOptions is not a function](/img/c9/0d92891b6beec3d6085bd3da516f00.png)
[记录]TypeError: this.getOptions is not a function

arcMap 发布切片服务

White screen processing method of fulter startup page

5 minutes to achieve wechat cloud applet payment function (including source code)

Build intelligent garbage classification applet based on Zero
随机推荐
Openlayers 5.0 loading ArcGIS Server slice service
数据分析学习目录
JVM的类加载过程
JS to get the local IP address
Core concepts of rest
SSDB Foundation
Prefer composition to inheritance
[play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
Pit encountered using camera x_ When onpause, the camera is not released, resulting in a black screen when it comes back
On the forced conversion of C language pointer
ArcMap connecting ArcGIS Server
精简CUDA教程——CUDA Driver API
Solve the problem of invalid listview Click
Redis optimization series (III) solve common problems after master-slave configuration
Coordinate conversion WGS-84 to gcj-02 and gcj-02 to WGS-84
The platinum library cannot search the debug process records of some projection devices
C1000k TCP connection upper limit test 1
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
Redis core technology and practice 1 - start with building a simple key value database simplekv
JS controls the file type and size when uploading files