get ip,mac

 DWORD  Err; 
        PFIXED_INFO  pFixedInfo; 
        DWORD  FixedInfoSize  =  0; 
        PIP_ADAPTER_INFO  pAdapterInfo,  pAdapt; 
        DWORD  AdapterInfoSize; 
        PIP_ADDR_STRING  pAddrStr; 
        Memo1->Lines->Clear(); 
  //  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) 
                  { 
                          Memo1->Lines->Add("GetNetworkParams  sizing  failed  with  error"+AnsiString(Err)); 
                          return; 
                  } 
          } 
 
          //  Allocate  memory  from  sizing  information 
          if  ((pFixedInfo  =  (PFIXED_INFO)  GlobalAlloc(GPTR,  FixedInfoSize))  ==  NULL) 
          { 
                  Memo1->Lines->Add("Memory  allocation  error"); 
                  return; 
          } 
 
          if  ((Err  =  GetNetworkParams(pFixedInfo,  &FixedInfoSize))  ==  0) 
          { 
                  Memo1->Lines->Add("Host  Name  :"+AnsiString(pFixedInfo->HostName)); 
                  pAddrStr  =  pFixedInfo->DnsServerList.Next; 
 
          } 
        else 
          { 
                  Memo1->Lines->Add("GetNetworkParams  failed  with  error  "+Err); 
                  return; 
          } 
 
          // 
          //  Enumerate  all  of  the  adapter  specific  information  using  the  IP_ADAPTER_INFO  structure. 
          //  Note:    IP_ADAPTER_INFO  contains  a  linked  list  of  adapter  entries. 
          // 
          AdapterInfoSize  =  0; 
          if  ((Err  =  GetAdaptersInfo(NULL,  &AdapterInfoSize))  !=  0) 
          { 
                  if  (Err  !=  ERROR_BUFFER_OVERFLOW) 
                  { 
                          Memo1->Lines->Add("GetAdaptersInfo  sizing  failed  with  error  "+Err); 
                          return; 
                  } 
          } 
 
          //  Allocate  memory  from  sizing  information 
          if  ((pAdapterInfo  =  (PIP_ADAPTER_INFO)  GlobalAlloc(GPTR,  AdapterInfoSize))  ==  NULL) 
          { 
                  Memo1->Lines->Add("Memory  allocation  error/n"); 
                  return; 
          } 
 
          //  Get  actual  adapter  information 
          if  ((Err  =  GetAdaptersInfo(pAdapterInfo,  &AdapterInfoSize))  !=  0) 
          { 
                  Memo1->Lines->Add("GetAdaptersInfo  failed  with  error  %d/n"+Err); 
                  return; 
          } 
 
          pAdapt  =  pAdapterInfo; 
 
          while  (pAdapt) 
          { 
                  int  i=1; 
                  Memo1->Lines->Add("Physical  Address  :  "); 
                  String  str=""; 
                  for  (int  i=0;  i <6;  i++) 
                  { 
                          if  (i>0) 
                    str=str+"-"; 
                    str=str+IntToHex(int(pAdapt->Address[i]),2); 
                  } 
                  Memo1->Lines->Add(str);                 
                  pAddrStr  =  &(pAdapt->IpAddressList); 
                  while(pAddrStr) 
                  { 
                          Memo1->Lines->Add("IP  Address  :  "+AnsiString(pAddrStr->IpAddress.String)); 
                          pAddrStr  =  pAddrStr->Next; 
                  } 
                  while(pAddrStr) 
                  { 
                          Memo1->Lines->Add(AnsiString(pAddrStr->IpAddress.String)); 
                          pAddrStr  =  pAddrStr->Next; 
                  } 
                  pAdapt  =  pAdapt->Next; 
                 
          } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值