FunctionCommon.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:PhonePerformanceMeasure 作者: KyleCe 项目源码 文件源码
def get_my_ip():
    """
    Returns the actual ip of the local machine.
    This code figures out what source address would be used if some traffic
    were to be sent out to some well known address on the Internet. In this
    case, a Google DNS server is used, but the specific address does not
    matter much.  No traffic is actually sent.
    """
    try:
        csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        csock.connect(('8.8.8.8', 80))
        (addr, port) = csock.getsockname()
        csock.close()
        return addr
    except socket.error:
        return "127.0.0.1"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号