当前位置:网站首页>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
边栏推荐
- How to solve the complexity of project document management?
- Windows MySQL 8 zip installation
- Cuisine leetcode
- Day 3 of learning rhcsa
- Solve the problem that the registered Google email Gmail mobile number cannot be used for verification
- Modify the content of MySQL + PHP drop-down box
- Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl
- Redis data server / database / cache (2022)
- How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year
- Leangoo brain map - shared multi person collaborative mind mapping tool
猜你喜欢

打靶narak

Android 高阶面试必问:全局业务和项目的架构设计与重构

ROP Emporium x86_64 7~8题

Using go language to build web server

Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl

Modify the content of MySQL + PHP drop-down box

Implementation of distributed scenario business operation log (based on redis lightweight)

The interface request takes too long. Jstack observes the lock holding

Flink stream processing engine system learning (III)

JVM runtime data area (I)
随机推荐
基于Scrum进行创新和管理
JZ76 删除链表中重复的结点
Rhcsa day 3 operation
Solve the problem that the registered Google email Gmail mobile number cannot be used for verification
First day of rhcsa
Essential qualities of advanced programmers
How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year
windows MySQL8 zip安装
JZ35 replication of complex linked list
进阶上将程序员必备素质
How to build an integrated industrial Internet plus hazardous safety production management platform?
基于Torchserve部署SBERT模型<语义相似度任务>
JZ22 鏈錶中倒數最後k個結點
JSON data text
JVM类加载器
Shell script learning notes -- shell operation on files sed
Water diversion into chengluo Valley p1514
Kubernetes study notes
JDBC JDBC
Looking for a job, writing a resume to an interview, this set of information is enough!