时间:2021-05-19
效果如下:
具体代码如下:
复制代码 代码如下:
#include <Windows.h>
#include <IPHlpApi.h>
#include <stdio.h>
#pragma comment(lib, "IPHlpApi")
#pragma comment(lib, "ws2_32")
int main(int argc, char **argv)
{
PIP_ADAPTER_INFO pAdapterInfo = NULL;
ULONG ulLen = sizeof(IP_ADAPTER_INFO);
struct tm newtime;
char szBuffer[32];
errno_t error;
//为适配器结构申请内存
//pAdapterInfo = (PIP_ADAPTER_INFO)GlobalAlloc(GPTR, ulLen);
pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
if (NULL == pAdapterInfo)
{
printf("Error allocating memory needed to call GetAdaptersInfo.\n");
return 1;
}
if (ERROR_BUFFER_OVERFLOW == GetAdaptersInfo(pAdapterInfo, &ulLen))
{
HeapFree(GetProcessHeap(), 0, pAdapterInfo);
pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, ulLen);
if (NULL == pAdapterInfo)
{
printf("Error allocating memory needed to call GetAdaptersInfo.\n");
return 1;
}
}
//取得本地适配器结构信息
if (ERROR_SUCCESS != GetAdaptersInfo(pAdapterInfo, &ulLen))
{
printf("GetAdaptersInfo error!\n");
return 0;
}
if (NULL == pAdapterInfo)
{
printf("There is no adapters!\n");
return 0;
}
SetConsoleTitle(TEXT("本地网卡适配器信息"));
do
{
printf("ComboIndex:%d\n", pAdapterInfo->ComboIndex);
printf("Adapter Name:%s\n", pAdapterInfo->AdapterName);
printf("Adapter Desc:%s\n", pAdapterInfo->Description);
printf("Adapter Addr:");
for (size_t i = 0; i < pAdapterInfo->AddressLength; i++)
{
if (i == (pAdapterInfo->AddressLength - 1))
{
printf("%02X", (int)pAdapterInfo->Address[i]);
}
else
{
printf("%02X-", (int)pAdapterInfo->Address[i]);
}
}
printf("\n");
printf("Index:%d\n", pAdapterInfo->Index);
printf("Type:");
switch (pAdapterInfo->Type)
{
case MIB_IF_TYPE_OTHER:printf("Other\n"); break;
case MIB_IF_TYPE_ETHERNET:printf("Ethernet\n"); break;
case MIB_IF_TYPE_TOKENRING:printf("Token Ring\n"); break;
case MIB_IF_TYPE_FDDI:printf("FDDI\n"); break;
case MIB_IF_TYPE_PPP:printf("PPP\n"); break;
case MIB_IF_TYPE_LOOPBACK:printf("Lookback\n"); break;
case MIB_IF_TYPE_SLIP:printf("Slip\n"); break;
default:printf("Unknow type %ld\n", pAdapterInfo->Type); break;
}
printf("IP Address:%s\n", pAdapterInfo->IpAddressList.IpAddress.String);
printf("IP Mask:%s\n", pAdapterInfo->IpAddressList.IpMask.String);
printf("Gateway:%s\n", pAdapterInfo->GatewayList.IpAddress.String);
if (pAdapterInfo->DhcpEnabled)
{
printf("DHCP Enabled:Yes\n");
printf("DHCP Server:%s\n", pAdapterInfo->DhcpServer.IpAddress.String);
printf("Lease Obtained:");
error = _localtime32_s(&newtime, (__time32_t*)&pAdapterInfo->LeaseObtained);
if (error)
{
printf("Invalid Argument to _localtime32_s.\n");
}
else
{
error = asctime_s(szBuffer, 32, &newtime);
if (error)
{
printf("Invalid Argument to asctime_s.\n");
}
else
{
printf("%s", szBuffer);
}
}
printf("Lease Expires:");
error = _localtime32_s(&newtime, (__time32_t*)&pAdapterInfo->LeaseExpires);
if (error)
{
printf("Invalid Argument to _localtime32_s.\n");
}
else
{
error = asctime_s(szBuffer, 32, &newtime);
if (error)
{
printf("Invalid Argument to asctime_s.\n");
}
else
{
printf("%s", szBuffer);
}
}
}
else
{
printf("DHCP Enabled:No\n");
}
if (pAdapterInfo->HaveWins)
{
printf("Have Wins:Yes\n");
printf("Primary Wins Server:%s\n", pAdapterInfo->PrimaryWinsServer.IpAddress.String);
printf("Secondary Wins Server:%s\n", pAdapterInfo->SecondaryWinsServer.IpAddress.String);
}
else
{
printf("Have Wins:No\n");
}
printf("=================================================================\n");
pAdapterInfo = pAdapterInfo->Next;
} while (pAdapterInfo);
if (pAdapterInfo)
{
HeapFree(GetProcessHeap(), 0, pAdapterInfo);
}
return 0;
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
需要用到本地蓝牙适配器//获取本地蓝牙适配器mBluetoothAdapter=BluetoothAdapter.getDefaultAdapter();判断是
【更改适配器设置】,在【本地连接】的选项属性中打开【internet协议版本4】属性,选择自动获取地址即可。具体介绍如下:再点击左侧的【更改适配器设置】,打开的
网卡的正式名称为网络适配器或网络接口卡。网络适配器又称网卡或网络接口卡(NIC),英文名NetworkInterfaceCard。 Emulex网络适配器的内
本文实例讲述了Java适配器模式应用之电源适配器功能。分享给大家供大家参考,具体如下:一、模式定义存在两种适配器模式1对象适配器模式,在这种适配器模式中,适配器
电脑主板自带网卡。 网络适配器又称网卡或网络接口卡(NIC),英文名NetworkInterfaceCard。Emulex网络适配器的内核是链路层控制器,该控