当前位置:网站首页>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
边栏推荐
- [wechat applet] set the bottom menu (tabbar) for the applet
- 期中汇总(概论+应用层+运输层)
- Solve the problem that PowerShell mining occupies 100% of cpu7 in win7
- Kubernetes - detailed explanation of pod
- The second day of learning rhcsa
- Download the genuine origin Pro 2022 tutorial and how to activate it
- Preliminary understanding of stack and queue
- Innovation and management based on Scrum
- OCR recognition PDF file
- 能做多大的单片机项目程序开发,就代表了你的敲代码的水平
猜你喜欢

【Hcip】OSPF常用的6种LSA详解

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

Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad

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

Machine learning (Zhou Zhihua) Chapter 14 probability graph model

Kubernetes study notes
![[wechat applet] set the bottom menu (tabbar) for the applet](/img/e2/98711dfb1350599cbdbdf13508b84f.png)
[wechat applet] set the bottom menu (tabbar) for the applet

Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op

Airtrack cracking wireless network password (Dictionary running method)

How to solve the complexity of project document management?
随机推荐
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
The usage of case when and select case when is very easy to use
Specific field information of MySQL export table (detailed operation of Navicat client)
Codeforces round 784 (Div. 4) (a - H)
Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
ele之Table表格的封装
《信息系统项目管理师总结》第六章 项目人力资源管理
Deploying sbert model based on torchserve < semantic similarity task >
[XJTU computer network security and management] Lecture 2 password technology
Classification and regression tree of machine learning
Classification of technology selection (2022)
Innovation and management based on Scrum
JZ76 删除链表中重复的结点
Rhcsa day 1 operation
Error installing Mongo service 'mongodb server' on win10 failed to start
If MySQL / SQL server judges that the table or temporary table exists, it will be deleted
C language 171 Number of recent palindromes
第46届ICPC亚洲区域赛(昆明) B Blocks(容斥+子集和DP+期望DP)
5W of knowledge points
Hack the box optimum