Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/01/2014, 00:13
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Obtener ip externa

Ahí tienes
Código Python:
Ver original
  1. #!/usr/bin/env python
  2.  
  3. import urllib2
  4. import re
  5. from BeautifulSoup import BeautifulSoup
  6.  
  7. soup = BeautifulSoup(urllib2.urlopen("http://www.geoiptool.com"))
  8. geoip = soup.title.string
  9. geoip = re.findall(r"\d+[.]\d+[.]\d+[.]\d+", geoip)[0]
  10.  
  11. print geoip

Otro script sin usar tantas librerías
Código Python:
Ver original
  1. #!/usr/bin/env python
  2.  
  3. import urllib2
  4.  
  5. f = urllib2.urlopen("http://icanhazip.com/")
  6. ip = f.read().strip()
  7. f.close()
  8. print ip

Última edición por razpeitia; 14/01/2014 a las 00:19