IPAddress:=GetIPAddress_1()
MsgBox % IPAddress.length() "`n" IPAddress[1,1]
GetIPAddress_1(){
  Adlist:=[], info:=GetAdaptersInfo()
  for index, obj in info
  {
    if !InStr(obj["Description"],"Adapter")&&!InStr(obj["IpAddressList"],"0.0.0.0")||obj["Description"] ~="i)Wifi|wlan"&&!InStr(obj["IpAddressList"],"0.0.0.0") {
      Adlist.Push([obj["IpAddressList"]," " . obj["Description"] . " ","〔 " . obj["Description"] . " 〕"])
    }
  }
  return Adlist
}

  ;获取网卡mac地址
GetAdaptersInfo(){
  ; 对GetAdaptersInfo的初始调用以获取所需的大小
  if (DllCall("iphlpapi.dll\GetAdaptersInfo", "ptr", 0, "UIntP", size) = 111) ; ERROR_BUFFER_OVERFLOW
    if !(VarSetCapacity(buf, size, 0))  ; size ==>  1x = 704  |  2x = 1408  |  3x = 2112
      return "IP适配器信息结构的内存分配失败!"
  ; 第二次调用GetAdapters地址以获取我们想要的实际数据
  if (DllCall("iphlpapi.dll\GetAdaptersInfo", "ptr", &buf, "UIntP", size) != 0) ; NO_ERROR / ERROR_SUCCESS
    return "调用GetAdaptersInfo失败,ERROR: " A_LastError
  ; 从数据中获取信息
  addr := &buf, IP_ADAPTER_INFO := {}
  while (addr)
  {
    IP_ADAPTER_INFO[A_Index, "ComboIndex"]:= NumGet(addr+0, o := A_PtrSize, "UInt"), o += 4
    IP_ADAPTER_INFO[A_Index, "AdapterName"]:= StrGet(addr+0 + o, 260, "CP0"), o += 260
    IP_ADAPTER_INFO[A_Index, "Description"]:= StrGet(addr+0 + o, 132, "CP0"), o += 132
    IP_ADAPTER_INFO[A_Index, "AddressLength"]:= NumGet(addr+0, o, "UInt"), o += 4
    loop % IP_ADAPTER_INFO[A_Index].AddressLength
      mac .= Format("{:02X}",NumGet(addr+0, o + A_Index - 1, "UChar")) "-"
    IP_ADAPTER_INFO[A_Index, "Address"]:= SubStr(mac, 1, -1), mac := "", o += 8
    IP_ADAPTER_INFO[A_Index, "Index"]:= NumGet(addr+0, o, "UInt"), o += 4
    IP_ADAPTER_INFO[A_Index, "Type"]:= NumGet(addr+0, o, "UInt"), o += 4
    IP_ADAPTER_INFO[A_Index, "DhcpEnabled"]:= NumGet(addr+0, o, "UInt"), o += A_PtrSize
    Ptr := NumGet(addr+0, o, "UPtr"), o += A_PtrSize
    IP_ADAPTER_INFO[A_Index, "CurrentIpAddress"]:= Ptr ? StrGet(Ptr + A_PtrSize, "CP0") : ""
    IP_ADAPTER_INFO[A_Index, "IpAddressList"]:= StrGet(addr + o + A_PtrSize, "CP0")
    ;~ IP_ADAPTER_INFO[A_Index, "IpMaskList"]:= StrGet(addr + o + A_PtrSize + 16, "CP0") , o += A_PtrSize + 32 + A_PtrSize
    IP_ADAPTER_INFO[A_Index, "IpMaskList"]:= StrGet(addr + o + A_PtrSize * 3, "CP0") , o += A_PtrSize + 32 + A_PtrSize
    IP_ADAPTER_INFO[A_Index, "GatewayList"]:= StrGet(addr + o + A_PtrSize, "CP0"), o += A_PtrSize + 32 + A_PtrSize
    IP_ADAPTER_INFO[A_Index, "DhcpServer"]:= StrGet(addr + o + A_PtrSize, "CP0"), o += A_PtrSize + 32 + A_PtrSize
    IP_ADAPTER_INFO[A_Index, "HaveWins"]:= NumGet(addr+0, o, "Int"), o += A_PtrSize
    IP_ADAPTER_INFO[A_Index, "PrimaryWinsServer"]:= StrGet(addr + o + A_PtrSize, "CP0"), o += A_PtrSize + 32 + A_PtrSize
    IP_ADAPTER_INFO[A_Index, "SecondaryWinsServer"] := StrGet(addr + o + A_PtrSize, "CP0"), o += A_PtrSize + 32 + A_PtrSize
    IP_ADAPTER_INFO[A_Index, "LeaseObtained"]:= DateAdd(NumGet(addr+0, o, "Int")), o += A_PtrSize
    IP_ADAPTER_INFO[A_Index, "LeaseExpires"]:= DateAdd(NumGet(addr+0, o, "Int"))
    addr := NumGet(addr+0, "UPtr")
  }
  ; 输出数据并释放缓冲区
  return IP_ADAPTER_INFO, VarSetCapacity(buf, 0), VarSetCapacity(addr, 0)
}

DateAdd(time)
{
  if (time = 0)
    return 0
  datetime := 19700101
  datetime += time, s
  FormatTime, OutputVar, datetime, yyyy-MM-dd HH:mm:ss
  return OutputVar
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。