Skip to content

Commit

Permalink
fix: 🐛 fix get_global_ip error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
onionj committed Mar 30, 2024
1 parent 13ae46a commit 43330cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pybotnet/package_info.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "2.2.4"
__version__ = "2.2.5"
__github_link__ = "https://github.com/onionj/pybotnet"
33 changes: 27 additions & 6 deletions pybotnet/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@
# Servers to get your public IP


def _get_my_ip_server_0():
"""return global ip V4 and contry code \n
server 1"""
takeip = requests.post("http://yourip.top/json", timeout=3).text
json_res = json.loads(takeip)
ip = str(json_res["ip"])
country = str(json_res["country"])
ipaddr = f"{ip}\ncountry_code: {country}"
return ipaddr


def _get_my_ip_server_1():
"""return global ip V4 and loaction \n
server 1"""
takeip = requests.post("https://api.myip.com", timeout=2).text
ip = str(json.loads(takeip)["ip"])
country = str(json.loads(takeip)["country"])
json_res = json.loads(takeip)
ip = str(json_res["ip"])
country = str(json_res["country"])
ipaddr = f"{ip}\ncountry: {country}"
return ipaddr

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


def get_global_ip() -> str:
"""return system ip (3 API server)"""
for server in [_get_my_ip_server_1, _get_my_ip_server_2, _get_my_ip_server_3]:
"""return system ip (4 API server)"""
for server in [
_get_my_ip_server_0,
_get_my_ip_server_1,
_get_my_ip_server_2,
_get_my_ip_server_3,
]:
try:
return server()
except:
return None
pass

return None


def get_host_name_ip() -> dict:
try:
host_name = socket.gethostname()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("4.2.2.4", 80))
host_ip = s.getsockname()[0]
s.close()
return {"host_ip": host_ip, "host_name": host_name}
except:
except Exception:
return {"host_ip": None, "host_name": None}
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
KEYWORDS = [
"onionj pybotnet",
"python remote control",
"python trojan",
"python backdoor",
"python botnet",
"pybotnet",
Expand Down

0 comments on commit 43330cf

Please sign in to comment.