# -*- coding: utf -8 -*-
from socket import gethostname, gethostbyname
from exceptions import AssertionError
def get_local_ip():
'''
Return local host ip.
'''
ip = gethostbyname(gethostname())
assert ip != '127.0.1.1', 'No network connect, please the network connect again!' # 不应该是怎样的,就写成怎样
return ip
try:
print get_local_ip()
except AssertionError, e:
print e
$ python get_localhost_ip.py
No network connect, please the network connect again!
本文介绍了一个使用Python编写的脚本,用于获取本地主机的IP地址,并处理了网络连接异常的情况。
1689

被折叠的 条评论
为什么被折叠?



