Skip to content

Commit 43330cf

Browse files
committed
fix: 🐛 fix get_global_ip error handling
1 parent 13ae46a commit 43330cf

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

pybotnet/package_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "2.2.4"
1+
__version__ = "2.2.5"
22
__github_link__ = "https://github.com/onionj/pybotnet"

pybotnet/utils/utils.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@
66
# Servers to get your public IP
77

88

9+
def _get_my_ip_server_0():
10+
"""return global ip V4 and contry code \n
11+
server 1"""
12+
takeip = requests.post("http://yourip.top/json", timeout=3).text
13+
json_res = json.loads(takeip)
14+
ip = str(json_res["ip"])
15+
country = str(json_res["country"])
16+
ipaddr = f"{ip}\ncountry_code: {country}"
17+
return ipaddr
18+
19+
920
def _get_my_ip_server_1():
1021
"""return global ip V4 and loaction \n
1122
server 1"""
1223
takeip = requests.post("https://api.myip.com", timeout=2).text
13-
ip = str(json.loads(takeip)["ip"])
14-
country = str(json.loads(takeip)["country"])
24+
json_res = json.loads(takeip)
25+
ip = str(json_res["ip"])
26+
country = str(json_res["country"])
1527
ipaddr = f"{ip}\ncountry: {country}"
1628
return ipaddr
1729

@@ -29,19 +41,28 @@ def _get_my_ip_server_3():
2941

3042

3143
def get_global_ip() -> str:
32-
"""return system ip (3 API server)"""
33-
for server in [_get_my_ip_server_1, _get_my_ip_server_2, _get_my_ip_server_3]:
44+
"""return system ip (4 API server)"""
45+
for server in [
46+
_get_my_ip_server_0,
47+
_get_my_ip_server_1,
48+
_get_my_ip_server_2,
49+
_get_my_ip_server_3,
50+
]:
3451
try:
3552
return server()
3653
except:
37-
return None
54+
pass
55+
56+
return None
57+
3858

3959
def get_host_name_ip() -> dict:
4060
try:
4161
host_name = socket.gethostname()
4262
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
4363
s.connect(("4.2.2.4", 80))
4464
host_ip = s.getsockname()[0]
65+
s.close()
4566
return {"host_ip": host_ip, "host_name": host_name}
46-
except:
67+
except Exception:
4768
return {"host_ip": None, "host_name": None}

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
KEYWORDS = [
2626
"onionj pybotnet",
2727
"python remote control",
28-
"python trojan",
2928
"python backdoor",
3029
"python botnet",
3130
"pybotnet",

0 commit comments

Comments
 (0)