CheckGateway.ps1 1.2 KB

12345678910111213141516171819202122232425262728
  1. $IP = (Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.IPEnabled}).DefaultIPGateway
  2. $MACAddressList = (Get-NetNeighbor -State Reachable)
  3. foreach ($item in $MACAddressList) {
  4. $AdresseIP = $item.IPAddress
  5. $AdresseMAC = $item.LinkLayerAddress
  6. if ($IP -contains $AdresseIP){$GatewayMac = $AdresseMAC ; $GatewayIP = $AdresseIP}
  7. }
  8. $PublicIP = ((Resolve-DnsName -Name myip.opendns.com -Server resolver1.opendns.com).IPAddress)
  9. $MacFreebox = "F4-CA-E5","00-07-CB","00-24-D4","14-0C-76","34-27-92","68-A3-78","70-FC-8F","8C-97-EA","E4-9E-12"
  10. $MacLivebox = "00-37-B7"
  11. $MacApple = "BC-B8-63"
  12. $MacXiaomi = "E0-CC-F8"
  13. $MacFortinet = "08-5B-0E"
  14. $MacSplit = $GatewayMac -split "-"
  15. $MacPrefix = $MacSplit[0] + "-" + $MacSplit[1] + "-" + $MacSplit[2]
  16. $Router = (Invoke-WebRequest -Uri "https://api.macvendors.com/$MacPrefix").Content
  17. $ShodanLink = "https://api.shodan.io/shodan/host/" + $PublicIP + "?key=9r6vVczYqYGR9F3WADASttMPt6fqK2Mm"
  18. $Shodan = Invoke-RestMethod -uri $ShodanLink
  19. $ISP = $Shodan.isp
  20. if ($Router -eq ""){"Gateway vendor is unknown ($GatewayMac). `nLocal IP is $AdresseIP. `nPublic IP is $PublicIP."}
  21. else{
  22. Write-Host "Gateway vendor is $Router ($GatewayMac). `nLocal IP is $AdresseIP. `nPublic IP is $PublicIP ($ISP)."}