-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgraded to a general minecraft server monitor program; added setting…
…s.json; updated readme; updated .gitignore
- Loading branch information
9FS
committed
Jan 13, 2024
1 parent
e89b4ae
commit 9fe0b7e
Showing
10 changed files
with
460 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
.hypothesis/ | ||
.pytest_cache/ | ||
doc_templates/ | ||
config/ | ||
log/ | ||
|
||
Dockerfile | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
aiohttp==3.8.6 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
aiohttp==3.9.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
aiosignal==1.3.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
async-timeout==4.0.3 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
asyncio-dgram==2.1.2 ; python_full_version >= "3.11.0" and python_version < "4" | ||
attrs==23.1.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
certifi==2023.7.22 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
attrs==23.2.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
certifi==2023.11.17 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
charset-normalizer==3.3.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
colorama==0.4.6 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
discord-py==2.3.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
discord==2.3.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
dnspython==2.4.2 ; python_full_version >= "3.11.0" and python_version < "4.0" | ||
frozenlist==1.4.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
idna==3.4 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
kfsconfig==1.0.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
frozenlist==1.4.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
idna==3.6 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
kfsconfig==1.1.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
kfsfstr==1.1.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
kfslog==1.0.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
kfsmath==1.0.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
mcstatus==11.0.1 ; python_full_version >= "3.11.0" and python_version < "4" | ||
mcstatus==11.1.1 ; python_full_version >= "3.11.0" and python_version < "4" | ||
multidict==6.0.4 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
requests==2.31.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
urllib3==2.0.7 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
yarl==1.9.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
urllib3==2.1.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" | ||
yarl==1.9.4 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (c) 2023 구FS, all rights reserved. Subject to the MIT licence in `licence.md`. | ||
import inspect | ||
import ipaddress | ||
import logging | ||
import requests | ||
import socket | ||
|
||
|
||
def convert_to_ip_public(ip_or_domain: str, ip_public_version: int=4) -> str: | ||
""" | ||
Converts given IP or domain, which may me local or public, to a guaranteed public IP using "https://ident.me/". | ||
Arguments: | ||
- ip_or_domain: IP given to convert | ||
- ip_public_version: try to convert to IPv4 or IPv6, if fails will fallback to other version, if fails again try any version, if fails again raises ValueError | ||
Returns: | ||
- ip_public: converted IP, guaranteed public | ||
Raises: | ||
- ValueError: IP or domain cannot be converted to IP object. | ||
- TimeoutError: Converting given IP or domain to public IP via "https://ident.me/" timed out. | ||
""" | ||
|
||
ip: ipaddress.IPv4Address|ipaddress.IPv6Address # ip which may be local or public | ||
ip_public: ipaddress.IPv4Address|ipaddress.IPv6Address # ip that is guaranteed public, result | ||
TIMEOUT: int=50 # internet connection timeout | ||
|
||
|
||
if ip_public_version not in (4, 6): | ||
logging.error(f"ip_public_version ({ip_public_version}) must be 4 or 6.") | ||
raise ValueError(f"Error in {convert_to_ip_public.__name__}{inspect.signature(convert_to_ip_public)}: ip_public_version ({ip_public_version}) must be 4 or 6.") | ||
|
||
|
||
logging.info(f"Converting given IP or domain \"{ip_or_domain}\" to IP...") | ||
try: | ||
ip=ipaddress.ip_address(socket.gethostbyname(ip_or_domain)) # convert IP or domain to IP, construct IP object | ||
except socket.gaierror: | ||
logging.error(f"\rConverting given IP or domain \"{ip_or_domain}\" to IP failed. Unable to get IP address information. Check the given domain/IP and the internet connection.") | ||
raise ValueError(f"Error in {convert_to_ip_public.__name__}{inspect.signature(convert_to_ip_public)}: Converting given IP or domain \"{ip_or_domain}\" to IP failed. Unable to get IP address information. Check the given domain/IP and the internet connection.") | ||
logging.info(f"\rConverted given IP or domain \"{ip_or_domain}\" to IP \"{ip.exploded.upper()}\".") | ||
|
||
|
||
for _ in range(2): # try to convert to IPv4 or IPv6, if fails will fallback to other version | ||
logging.info(f"Converting given IP \"{ip.exploded.upper()}\" to public IPv{ip_public_version}...") | ||
try: | ||
ip_public=ipaddress.ip_address(requests.get(f"https://{ip_public_version}.ident.me/", timeout=TIMEOUT).text) # try to convert | ||
except TimeoutError: | ||
logging.error(f"\rConverting given IP \"{ip.exploded.upper()}\" to public IPv{ip_public_version} timed out.") | ||
ip_public_version=6 | ||
except ValueError as e: | ||
logging.error(f"\rConverting given IP \"{ip.exploded.upper()}\" to public IPv{ip_public_version} failed with ValueError. Network does not seem to have an IPv{ip_public_version}. Error message:\n{e.args}") | ||
match ip_public_version: # fallback to other version | ||
case 4: | ||
ip_public_version=6 | ||
case 6: | ||
ip_public_version=4 | ||
case _: | ||
logging.critical(f"ip_public_version ({ip_public_version}) is neither 4 nor 6 despite having checked earlier.") | ||
raise RuntimeError(f"Error in {convert_to_ip_public.__name__}{inspect.signature(convert_to_ip_public)}: ip_public_version ({ip_public_version}) is neither 4 nor 6 despite having checked earlier.") | ||
else: | ||
logging.info(f"\rConverted given IP \"{ip.exploded.upper()}\" to public IPv{ip_public_version} \"{ip_public.exploded.upper()}\".") | ||
match ip_public_version: # specific formatting depending on version | ||
case 4: | ||
return ip_public.exploded.upper() | ||
case 6: | ||
return f"[{ip_public.exploded.upper()}]" | ||
case _: | ||
logging.critical(f"ip_public_version ({ip_public_version}) is neither 4 nor 6 despite having checked earlier.") | ||
raise RuntimeError(f"Error in {convert_to_ip_public.__name__}{inspect.signature(convert_to_ip_public)}: ip_public_version ({ip_public_version}) is neither 4 nor 6 despite having checked earlier.") | ||
|
||
logging.info(f"Converting given IP \"{ip.exploded.upper()}\" to public IP...") # last ditch effort, try any version | ||
try: | ||
ip_public=ipaddress.ip_address(requests.get("https://ident.me/", timeout=TIMEOUT).text) # convert to public IP, don't care about IPv4 or IPv6 | ||
except TimeoutError: | ||
logging.error(f"\rConverting given IP \"{ip.exploded.upper()}\" to public IP timed out.") | ||
raise | ||
except ValueError as e: | ||
logging.error(f"\rConverting given IP \"{ip.exploded.upper()}\" to public IP failed with ValueError. Network does not seem to have an IP. Error message:\n{e.args}") | ||
raise | ||
else: | ||
logging.info(f"\rConverted given IP \"{ip.exploded.upper()}\" to public IP \"{ip_public.exploded.upper()}\".") | ||
return ip_public.exploded.upper() |
Oops, something went wrong.