IP2MAC(IP){ ;http://msdn.microsoft.com/library/en-us/iphlp/iphlp/sendarp.asp VarSetCapacity(ip_ulong, 4, 0) ip_ulong := DllCall("Ws2_32.dll\inet_addr", "str", ip) VarSetCapacity(pMacAddr, 6, 0) PhyAddrLen=6 r := DllCall("Iphlpapi.dll\SendARP", "uint", ip_ulong, "uint", 0, "uint", &pMacAddr, "uint", &PhyAddrLen) IfNotEqual, r, 0, return 0 int_format := A_FormatInteger SetFormat, Integer, Hex Loop, 6 { t := *(&pMacAddr + A_Index-1) StringTrimLeft, t, t, 2 t=0%t% StringRight, t, t, 2 res=%res%:%t% } StringTrimLeft, res, res, 1 StringUpper, res, res SetFormat, Integer, %int_format% Return, res } Ping(IP, MaxHops=30) { ;http://msdn.microsoft.com/library/en-us/iphlp/iphlp/getrttandhopcount.asp VarSetCapacity(ip_ulong, 4, 0) ip_ulong := DllCall("Ws2_32.dll\inet_addr", "str", ip) VarSetCapacity(HopCount, 4, 0) VarSetCapacity(RTT, 4, 0) r := DllCall("Iphlpapi.dll\GetRTTAndHopCount", "UInt", ip_ulong, "UInt", &HopCount, "UInt", MaxHops, "UInt", &RTT) If (r > 0) { Loop, 4 { rRTT += *(&RTT + A_Index-1) << 8*(A_Index-1) rHopCount += *(&HopCount + A_Index-1) << 8*(A_Index-1) } IfEqual, rRTT, 0, return, "localhost" return rRTT } else { return r } }
Sample code:
;show MAC addresses of the given IPs Loop, 4 { ip := A_IpAddress%a_index% msgbox % "IP: " . ip . "`nMAC: " . ip2mac(ip) } ;ping google.com msgbox % Ping("64.233.187.99")
Edit: Changed Ping to return "localhost" when the round trip time equals zero (rHopCount is 1 in this case). Thanks corrupt.