Skip to content

Instantly share code, notes, and snippets.

@KunihikoKido
Created August 1, 2013 08:03
Show Gist options
  • Save KunihikoKido/6129368 to your computer and use it in GitHub Desktop.
Save KunihikoKido/6129368 to your computer and use it in GitHub Desktop.
バブリックIP取得
# -*- coding: utf-8 -*-
import urllib2
def get_public_ipv4(ec2instance=False):
url = 'http://ip.42.pl/raw'
if ec2instance:
url = 'http://169.254.169.254/latest/meta-data/public-ipv4'
return '%s' % urllib2.urlopen(url).read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment