Conditions | 2 |
Total Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 1 |
CRAP Score | 4.916 |
1 | # -*- coding: utf-8 -*- |
||
38 | 10 | def get_external_ip(): |
|
39 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
||
40 | try: |
||
41 | wechat_ip = socket.gethostbyname('api.mch.weixin.qq.com') |
||
42 | sock.connect((wechat_ip, 80)) |
||
43 | addr, port = sock.getsockname() |
||
44 | sock.close() |
||
45 | return addr |
||
46 | except socket.error: |
||
47 | return '127.0.0.1' |
||
48 |