当前位置:网站首页>MFC obtains local IP (used more in network communication)
MFC obtains local IP (used more in network communication)
2022-07-01 17:47:00 【ToneSole】
CString CUDPDlg::GetIP() // Access to the local IP
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255]; // Local hostname array variable
CString m_ip; // IP Address string variable
PHOSTENT hostinfo; // hostent Structure pointer
wVersionRequested = MAKEWORD(2, 0); // Connecting applications to winsock Dll
if (WSAStartup(wVersionRequested, &wsaData) == 0)
{
if (gethostname(name, sizeof(name)) == 0) // Get the local host name
{
if ((hostinfo = gethostbyname(name)) != NULL) // Get host information
{
m_ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list); // Convert to get IP Address
}
else m_ip = "IP Detection failed ";
}
WSACleanup(); // suspend winsock DLL Use
}
return m_ip; // return IP Address string
}
Call the following
CString localIP;
localIP = GetIP(); // Get this machine IP
SetDlgItemText(IDC_IP1, localIP); // Get local IP Display to the interface
边栏推荐
- Software construction scheme of smart factory collaborative management and control application system
- SLO is increasingly used to achieve observability | Devops
- Good looking UI mall source code has been scanned, no back door, no encryption
- Htt [ripro network disk link detection plug-in] currently supports four common network disks
- DNS
- ACL 2022 | decomposed meta learning small sample named entity recognition
- What are the legal risks of NFT brought by stars such as curry and O'Neill?
- 深度优先遍历和广度优先遍历[通俗易懂]
- DNS
- SQL injection vulnerability (MySQL and MSSQL features)
猜你喜欢
Petrv2: a unified framework for 3D perception of multi camera images
vulnhub靶场-Hacker_Kid-v1.0.1
DNS
剑指 Offer 20. 表示数值的字符串
Heavy disclosure! Hundreds of important information systems have been invaded, and the host has become a key attack target
Mysql database - Advanced SQL statement (2)
(十七)DAC转换实验
Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
(17) DAC conversion experiment
Vulnhub range hacker_ Kid-v1.0.1
随机推荐
An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
pyqt5中,在控件上画柱状图
Unity3d extended toolbar
DNS
Encryption and decryption of tinyurl in leetcode
Gold, silver and four job hopping, interview questions are prepared, and Ali becomes the champion
Redis -- data type and operation
Good looking UI mall source code has been scanned, no back door, no encryption
Research Report on development prediction and investment direction of nylon filament sewing thread in China (2022 Edition)
February 16, 2022 Daily: graph neural network self training method under distribution and migration
Why should you consider using prism
Common design parameters of solid rocket motor
China acetonitrile market forecast and strategic consulting research report (2022 Edition)
Is the software of futures pioneer formal and safe? Which futures company is safer to choose?
Intelligent operation and maintenance practice: banking business process and single transaction tracking
The difference and relationship between iteratible objects, iterators and generators
字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
Glidefast consulting was selected as the elite partner of servicenow in 2022
[PHP foundation] realize the connection between PHP and SQL database
How to use JMeter function and mockjs function in metersphere interface test