python/dna/utils.py
def self_ip(public=False):
    ''' Utility for logbook information injection '''
    try:
        if public:
            data = str(urlopen('http://checkip.dyndns.com/').read())
            ip_addr = re.compile(
                r'Address: (\d+\.\d+\.\d+\.\d+)').search(data).group(1)
        else:
            sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            sock.connect(('google.com', 0))
            ip_addr = sock.getsockname()[0]
    except Exception, error:
        print('Online test failed : {}'.format(error))
        raise
    return ip_addr
def self_ip(public=False):
    ''' Utility for logbook information injection '''
    try:
        if public:
            data = str(urlopen('http://checkip.dyndns.com/').read())
            ip_addr = re.compile(
                r'Address: (\d+\.\d+\.\d+\.\d+)').search(data).group(1)
        else:
            sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            sock.connect(('google.com', 0))
            ip_addr = sock.getsockname()[0]
    except Exception, error:
        print('Online test failed : {}'.format(error))
        raise
    return ip_addr
Utility for logbook information injection