给大家一段可以查看网卡IP和子网的代码

___NULL 2006-12-15 12:30:41
实际上察看IP和子网只是我现在的程序需要,里面还有不少属性可以调用
主要 API GetNetworkParams() 和 GetAdaptersInfo()

/*
向项目中添加
C:\Program Files\Borland\BDS\4.0\lib\psdk\iphlpapi.lib
文件
*/

#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <time.h>

void __fastcall TForm3::Button1Click(TObject *Sender)
{
DWORD Err;

PFIXED_INFO pFixedInfo;
DWORD FixedInfoSize = 0;

PIP_ADAPTER_INFO pAdapterInfo, pAdapt;
DWORD AdapterInfoSize;
PIP_ADDR_STRING pAddrStr;

//
// Get the main IP configuration information for this machine using a FIXED_INFO structure
//
if ((Err = GetNetworkParams(NULL, &FixedInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
// printf("GetNetworkParams sizing failed with error %d\n", Err);
return;
}
}

// Allocate memory from sizing information
if ((pFixedInfo = (PFIXED_INFO) GlobalAlloc(GPTR, FixedInfoSize)) == NULL)
{
// printf("Memory allocation error\n");
return;
}

AdapterInfoSize = 0;

if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
// printf("GetAdaptersInfo sizing failed with error %d\n", Err);
return;
}
}

if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL)
{
// printf("Memory allocation error\n");
return;
}

// Get actual adapter information
if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0)
{
// printf("GetAdaptersInfo failed with error %d\n", Err);
return;
}

pAdapt = pAdapterInfo;

ShowMessage(pAdapt->Description);

// ShowMessage(pAdapt->AdapterName);

pAddrStr = &(pAdapt->IpAddressList);

while(pAddrStr)
{
ShowMessage(pAddrStr->IpAddress.String);
ShowMessage(pAddrStr->IpMask.String);
pAddrStr = pAddrStr->Next;
}

}
//---------------------------------------------------------------------------
...全文
385 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sbkopoky 2007-02-17
  • 打赏
  • 举报
回复
有一个香港和悦网络电话的源文件 ,有兴趣妨进入我的BLOG看看
Klamath 2007-02-05
  • 打赏
  • 举报
回复
mark 谢谢
hz58499009 2007-02-04
  • 打赏
  • 举报
回复
谢谢!!!
睿音 2007-01-22
  • 打赏
  • 举报
回复
mark
jimmyevan 2007-01-22
  • 打赏
  • 举报
回复
有用!谢谢
hili 2007-01-08
  • 打赏
  • 举报
回复
mark
laowang2 2006-12-23
  • 打赏
  • 举报
回复
收了.

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧