#include<stdio.h>
#include<winsock2.h> //该头文件需在windows.h之前
#include<windows.h>
#include<string>
#include<iostream>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
void getIP()
{
WSADATA WSAData; //WSADATA结构被用来储存调用AfxSocketInit全局函数返回的Windows Sockets初始化信息。
if (WSAStartup(MAKEWORD(2, 0),&WSAData)) // 初始化Windows sockets API
{
printf("WSAStartup failed %s\n", WSAGetLastError());
exit(-1); //异常退出
}
char hostName[256];
if(gethostname(hostName,sizeof(hostName))) //获取主机名
{
printf("Error: %u\n", WSAGetLastError());
exit(-1); //异常退出
}
printf("主机名: %s\n", hostName);
hostent *host=gethostbyname(hostName); // 根据主机名获取主机信息.
if(host==NULL)
{
printf("Error: %u\n", WSAGetLastError());
exit(-1);
}
cout<<"主机地址类型: "<<host->h_addrtype<<endl
<<"地址清单: "<<host->h_addr_list<<endl
<<"别名列表: "<<host->h_aliases<<endl
<<"地址长度: "<<host->h_length<<endl
<<"正式的主机名: "<<host->h_name<<endl;
for(int i=0;host->h_addr_list[i]!=0;i++)
{
cout<<"该主机IP"<<i+1<<": "<<inet_ntoa(*(struct in_addr*)*host->h_addr_list)<<endl;
}
cout<<"-----------------------------------------------"<<endl;
WSACleanup();
}
void getSysInfo()
{
SYSTEM_INFO sysInfo; //该结构体包含了当前计算机的信息:计算机的体系结构、中央处理器的类型、系统中中央处理器的数量、页面的大小以及其他信息。
OSVERSIONINFOEX osvi;
GetSystemInfo(&sysInfo);
osvi.dwOSVersionInfoSize=sizeof(osvi);
if (GetVersionEx((LPOSVERSIONINFOW)&osvi))
{
printf("操作系统版本 : %u.%u.%u\n", osvi.dwMajorVersion, osvi.dwMinorVersion,osvi.dwBuildNumber);
printf("Service Pack : %u.%u\n", osvi.wServicePackMajor, osvi.wServicePackMinor);
}
printf("处理器架构 : %u\n", sysInfo.wProcessorArchitecture);
printf("处理器级别 : %u\n", sysInfo.wProcessorLevel);
printf("处理器版本 : %u\n", sysInfo.wProcessorRevision);
printf("处理器掩码 : %u\n", sysInfo.dwActiveProcessorMask);
printf("处理器数量 : %u\n", sysInfo.dwNumberOfProcessors);
printf("处理器类型 : %u\n", sysInfo.dwProcessorType);
printf("页面大小 : %u\n", sysInfo.dwPageSize);
printf("应用程序最小地址 : %u\n", sysInfo.lpMinimumApplicationAddress);
printf("应用程序最大地址 : %u\n", sysInfo.lpMaximumApplicationAddress);
printf("虚拟内存分配粒度 : %u\n", sysInfo.dwAllocationGranularity);
printf("OemId : %u\n", sysInfo.dwOemId);
printf("wReserved : %u\n", sysInfo.wReserved);
}
int main()
{
getIP();
getSysInfo();
return 0;
}
C/C++ 获取系统IP地址/硬件信息等
原创
©著作权归作者所有:来自51CTO博客作者LyShark的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
获取IP地址
端点(API接口)访问获取IP地址!
IP Java SpringBoot\ -
C/C++ 获取本机IP地址信息
【代码】C/C++ 获取本机IP地址信息。
c++ c语言 tcp/ip 开发语言 网络协议 -
C++ 硬件信息 获取网卡MAC地址
获取计算机网卡MAC地址的方法很多,这里采用的是命令行的形式获取,可以获取有线网卡与无
硬件 网卡 mac 命令行 #include -
C/C++ 获取线程入口地址模块等
今天检测的特征是向 YY语音 里插入了一段自己的代码(创建了新的线程),而这个新的线程不在原有的模块内,所以思路就是遍
c语言 c++ 开发语言 句柄 #pragma -
C++获取本机的ip地址程序
上面是头文件 源代码文件
#include 主机名 ios 其他 -
C++ 获取网卡名称和IP地址
这是获取网卡名称和IP地址的代码示例,参考自。原文描述得比较详细,但是没有输出物理地址,下面的代码进行了补充,在win10上测试能正常输出。
c++ tcp/ip 开发语言 mac 安全 -
C/C++ 获取函数地址
CC语言中没有类的概念,只有普通的函数。通过函数名就可以得到函数地址#include <std
成员函数 静态函数 成员变量 -
C++ 硬件信息 获取主板序列号
获取计算机网卡主板序列号的方法很多,这里采用的是命令行的形式获取,可以获取主板序列号,很简
硬件 主板 序列号 命令行 #include -
C++ 硬件信息 获取CPU序列号
获取计算机CPU序列号的方法很多,这里采用的是命令行的形式获取,可以获取CPU的序列号,很简单,直
硬件 cpu 序列号 命令行 #include -
java 整数 equals
/* 关于Java中的整数型 数据类型 占用空间 默认值 取值范围 -------------------------------------------------------------- byte 1 0 [-128~127] s
java 整数 equals java 字面值 强制类型转换 类型转换