21 lines
345 B
Python
21 lines
345 B
Python
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
import socket
|
||
|
|
||
|
|
||
|
def get_host_ip():
|
||
|
"""
|
||
|
查询本机ip地址
|
||
|
:return:
|
||
|
"""
|
||
|
_s = None
|
||
|
try:
|
||
|
_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||
|
_s.connect(('8.8.8.8', 80))
|
||
|
l_host = _s.getsockname()[0]
|
||
|
finally:
|
||
|
_s.close()
|
||
|
|
||
|
return l_host
|