0

I am trying to find the switch port that a network device (e.g. server) is plugged into (i.e. the hostname) and MAC address for the device (e.g. server). I can connect to the device just fine knowing the IP as follows:

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(self.TIMEOUT)
sock.connect_ex((ip_address, DEFAULT_PORT))

How do I get the MAC address and port name/number? The switches are Cisco but I don't want to rely on apriori knowledge about the network hardware.

MoreScratch
  • 2,933
  • 6
  • 34
  • 65

1 Answers1

0
import socket
print(socket.gethostname())

How can I use Python to get the system hostname?

Binh ED
  • 21
  • 1
  • That doesn't work for me. It gives me my machine hostname Mortons-iMac.local. I want the switch port which I know is S14M12. – MoreScratch Mar 12 '18 at 03:27