|
7 | 7 | import requests |
8 | 8 | import re |
9 | 9 | import platform |
10 | | -ip_pattern = r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}" |
11 | | -api_1 = "http://ipinfo.io/ip" |
| 10 | +IP_PATTERN = r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}" |
| 11 | +GLOBAL_IP_API_1 = "http://ipinfo.io/ip" |
12 | 12 |
|
13 | 13 |
|
14 | 14 | def internet(host="8.8.8.8", port=53, timeout=3): |
@@ -77,8 +77,8 @@ def global_ip(debug=False): |
77 | 77 | """ |
78 | 78 | try: |
79 | 79 | new_session = requests.session() |
80 | | - response = new_session.get(api_1) |
81 | | - ip_list = re.findall(ip_pattern, response.text) |
| 80 | + response = new_session.get(GLOBAL_IP_API_1) |
| 81 | + ip_list = re.findall(IP_PATTERN, response.text) |
82 | 82 | new_session.close() |
83 | 83 | return ip_list[0] |
84 | 84 | except Exception as e: |
@@ -111,7 +111,7 @@ def set_ip(ip, restart=False, device="eth0", debug=False): |
111 | 111 | dns-nameservers 8.8.8.8 8.8.4.4 |
112 | 112 | ''' |
113 | 113 | try: |
114 | | - if bool(re.match(ip_pattern, ip)) == False or ip.find( |
| 114 | + if bool(re.match(IP_PATTERN, ip)) == False or ip.find( |
115 | 115 | "192.168.") == -1 or device not in mac().keys(): |
116 | 116 | raise Exception("IP Formation Error") |
117 | 117 | static_string = static_string.replace("ip", ip) |
@@ -143,7 +143,7 @@ def ping(ip, packet_number=3, debug=False): |
143 | 143 | :return: a boolean value (True if ip is available and False otherwise) |
144 | 144 | """ |
145 | 145 | try: |
146 | | - if re.match(ip_pattern, ip) == False: |
| 146 | + if re.match(IP_PATTERN, ip) == False: |
147 | 147 | raise Exception("IP Formation Error") |
148 | 148 | output = str(list(sub.Popen(["ping", |
149 | 149 | ip, |
|
0 commit comments