Python 学习

获得请求主机IP

2020-01-14  本文已影响0人  bianruifeng
from falsk import request

def get_request_ip():
    '''获取请求方的ip'''
    try:
        ip = request.remote_addr
        logging.error('------ ip = %s ------' % ip)
        return ip
    except Exception as e:
        logging.error(e)


def get_my_ip():
    '''获取本机的ip'''
    try:
 
        name = socket.getfqdn(socket.gethostname())
        ip = socket.gethostbyname(name)
        logging.error('------ ip = %s ------' % ip)
        return ip
    except Exception as e:
        logging.error(e)
上一篇下一篇

猜你喜欢

热点阅读