How to get all ips associated with some domain with Python?

0

I need to create an application that gets all the ips associated with some domain. I tried using the following code in Python:

import socket

print(socket.gethostbyname('facebook.com.br'))

However, it only returns me an IP. Is there a way to get the facebook range back, for example?

    
asked by anonymous 15.02.2017 / 02:25

2 answers

0

If you prefer an option that does not use Python, you can use Tracert in Windows, or Traceroute in Linux.

  

Output the code in Tracert

So you could use Python just to run the external command with the help of the subprocess library, instead of trying to use the language's own resources.

The code below executes the command and stores it in a .txt file

# 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')
    
24.02.2017 / 16:36
0

Good afternoon Gurion, I think the code below may help you:

import socket

lista_de_ip = []

site = socket.getaddrinfo("www.facebook.com.br" ,0)

for i in site:
  lista_de_ip.append(i[-1][0])
lista_de_ip = list(set(lista_de_ip))

print(lista_de_ip)

    
15.02.2017 / 19:32