If you prefer an option that does not use Python, you can use Tracert on Windows, or Traceroute on Linux.
Code output in Tracert
So you could use Python only to run the external command with the help of the library subprocess, instead of trying to use the resources of the language itself.
The code below executes the command and stores it in a file . txt
# coding: UTF-8
import os
import subprocess
# Se for Windows, apenas troque o traceroute por tracert
command = ['traceroute', 'www.facebook.com']
with open('log.txt', 'w') as arq:
output_command = subprocess.call(command, stdout=arq)
print('[+] Finished')
Have you tested this code? Does it really work? For me here it just generated a list with an IP and a MAC address...
– Luiz Vieira
Yes Luiz, I tried it and it really works! Did you make an error? For me it returns an IPV4 from facebook and another is an IPV6 (not MAC address) I put the output from my terminal, in the answer above. In my case presents these due to facebook caches in my city, in yours may be different.
– Mário Rodeghiero
You’re right, it’s an IPV6 and not a MAC address. Sorry for the misunderstanding.
– Luiz Vieira
right! And you need the IP’s in another format?
– Mário Rodeghiero