当前位置:网站首页>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
边栏推荐
- Shell script learning -- practical case
- 基于Torchserve部署SBERT模型<语义相似度任务>
- Classification of technology selection (2022)
- Navicat premium import SQL file
- LeetCode 1450 - 1453
- Linux Redis ——Redis HA Sentinel 集群搭建详解 & Redis主从部署
- Store consumption SMS notification template
- 机器学习(周志华) 第十四章概率图模型
- TypeScript(1)
- Jupyter for local and remote access to ECS
猜你喜欢

windows MySQL8 zip安装

grain rain

Those years can not do math problems, using pyhon only takes 1 minute?

Target narak

Windows MySQL 8 zip installation

First knowledge of C language ~ branch statements

How to build an integrated industrial Internet plus hazardous safety production management platform?

Kubernetes study notes

Modify the content of MySQL + PHP drop-down box

leangoo脑图-共享式多人协作思维导图工具分享
随机推荐
Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
First day of rhcsa
Rhcsa second day operation
Source code and some understanding of employee management system based on polymorphism
Rhcsa day 4 operation
Using go language to build web server
高效音乐格式转换工具Music Converter Pro
Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
5W of knowledge points
Microservices (distributed architecture)
Flink learning (XI) watermark
Linux Redis ——Redis HA Sentinel 集群搭建详解 & Redis主从部署
Flink stream processing engine system learning (I)
OCR recognition PDF file
leetcode 烹饪料理
OCR识别PDF文件
LeetCode 1450 - 1453
Liunx foundation - zabbix5 0 monitoring system installation and deployment
Planning code ROS migration POMDP prediction planning (I)
【Hcip】OSPF常用的6种LSA详解