Skip to content

Instantly share code, notes, and snippets.

@kylestev
Created May 5, 2013 20:48
Show Gist options
  • Select an option

  • Save kylestev/5522119 to your computer and use it in GitHub Desktop.

Select an option

Save kylestev/5522119 to your computer and use it in GitHub Desktop.
Get your IP from MaxMind using the requests and bs4 libraries in Python
from bs4 import BeautifulSoup
from requests import Session
MAXMIND_URL = 'http://www.maxmind.com/en/locate_my_ip'
def get_ip(sesh):
soup = BeautifulSoup(sesh.get(MAXMIND_URL).content)
return soup.find(id='my-ip-address').text
if __name__ == '__main__':
print get_ip(Session())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment