当前位置:网站首页>Winsock programming interface experiment: implementation of ipconfig
Winsock programming interface experiment: implementation of ipconfig
2022-04-23 02:51:00 【Mr_ atopos】
Rewrite the code in the book , Use C++
《Windows Network programming ( The first 2 edition )》
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <winsock2.h>
#include<iphlpapi.h>
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib,"iphlpapi.lib")
#include<iostream>
#include<sstream>
using namespace std;
void getInfo()
{
// Specify the pointer of the obtained network information structure linked list
IP_ADAPTER_INFO* pAdapterInfo;
// Save the length of the linked list of the obtained network information structure
ULONG ulOutBufLen;
// Return call code
DWORD dwRetVal;
// A single structure variable used to round through all network adapter information
PIP_ADAPTER_INFO pAdapter;
// by pAdapterInfo Allocate space
pAdapterInfo = NULL;//(IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
ulOutBufLen = 0;//sizeof(IP_ADAPTER_INFO);
// Get network card information
// The first 1 Secondary call GetAdaptersInfo(), Get the size of the returned result to ulOutBufLen in , The length of the linked list of network information structure
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW)
{
pAdapterInfo = new IP_ADAPTER_INFO[ulOutBufLen];
}
// The first 2 Secondary call GetAdaptersInfo(), Get the local network information to the structure pAdapterInfo in
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) != ERROR_SUCCESS)
{
cout<<"GetAdaptersInfo Error! :"<< dwRetVal<<endl;
}
// from pAdapterInfo Get and display local network information
pAdapter = pAdapterInfo;
while (pAdapter)
{
cout << endl;
cout << " Network adapter name :\t" << pAdapter->AdapterName << endl;
cout << "\n Network adapter description :\t" << pAdapter->Description << endl;
printf(" MAC Address : \t\t");
for (unsigned int i = 0; i < pAdapter->AddressLength; i++)
{
if (i == (pAdapter->AddressLength - 1))
printf("%.2X\n", (int)pAdapter->Address[i]);
else
printf("%.2X-", (int)pAdapter->Address[i]);
}
printf(" IP Address : \t\t%s\n", pAdapter->IpAddressList.IpAddress.String);
printf(" Subnet mask : \t\t%s\n", pAdapter->IpAddressList.IpMask.String);
printf(" gateway : \t\t%s\n", pAdapter->GatewayList.IpAddress.String);
if (pAdapter->DhcpEnabled)
{
printf(" Enable DHCP: \t\t yes \n");
printf(" DHCP The server : \t\t%s\n", pAdapter->DhcpServer.IpAddress.String);
}
else
{
printf(" Enable DHCP: \t\t no \n");
}
// Handle next person network adapter
pAdapter = pAdapter->Next;
}
// Release resources
if (pAdapterInfo)
delete pAdapter;
cout << endl;
}
int main()
{
getInfo();
return 0;
}
版权声明
本文为[Mr_ atopos]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220738105190.html
边栏推荐
- Jupyter for local and remote access to ECS
- Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow
- Planning code ROS migration POMDP prediction planning (I)
- Les derniers noeuds K de la liste jz22
- Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet
- [unity3d] rolling barrage effect in live broadcasting room
- PIP install shutil reports an error
- Learn regular expression options, assertions
- The usage of case when and select case when is very easy to use
- Redis data server / database / cache (2022)
猜你喜欢
Store consumption SMS notification template
Solve the problem that PowerShell mining occupies 100% of cpu7 in win7
Airtrack cracking wireless network password (Dictionary running method)
Interim summary (Introduction + application layer + transportation layer)
JVM类加载器
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
Flink stream processing engine system learning (I)
grain rain
Download the genuine origin Pro 2022 tutorial and how to activate it
Android high-level interview must ask: overall business and project architecture design and reconstruction
随机推荐
[XJTU computer network security and management] Lecture 2 password technology
The penultimate K nodes in jz22 linked list
Navicat premium import SQL file
TypeScript(1)
Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
Log4j知识点记录
[hcip] detailed explanation of six LSAS commonly used by OSPF
C language 171 Number of recent palindromes
基于Scrum进行创新和管理
Get together to watch (detailed version) eat a few cents a day
国产轻量级看板式Scrum敏捷项目管理工具
Android high-level interview must ask: overall business and project architecture design and reconstruction
grain rain
Classification of technology selection (2022)
【unity3D】直播间滚动式弹幕效果
The usage of case when and select case when is very easy to use
JZ22 鏈錶中倒數最後k個結點
Step principle of logical regression in machine learning
Learn regular expression options, assertions