import
socket
print(
'当前主机名称为 : ' +
socket.gethostname())
print(
'当前主机的IP为: ' +
socket.gethostbyname(
socket.gethostname()))
addrs =
socket.getaddrinfo(
socket.gethostname(),None)
for item in addrs:
print(
item)
print(
'当前主机IPV4地址为:' + [
item[
4][
0]
for item in addrs
if ':' not in item[
4][
0]][
0])
for item in addrs:
if ':' not in item[
4][
0]:
print(
'当前主机IPV4地址为:' +
item[
4][
0])
break
运行结果
转载于:https://www.cnblogs.com/bilaisheng/p/10211032.html
相关资源:python获取ip地址
转载请注明原文地址: https://mac.8miu.com/read-2046.html