mirror of https://gitlab.com/bashrc2/epicyon
Function to check if the internet is available
parent
d55ae90154
commit
3f6fea2716
14
epicyon.py
14
epicyon.py
|
@ -129,6 +129,7 @@ from poison import load_dictionary
|
||||||
from poison import load_2grams
|
from poison import load_2grams
|
||||||
from webapp_post import get_instance_software
|
from webapp_post import get_instance_software
|
||||||
from siteactive import site_is_active
|
from siteactive import site_is_active
|
||||||
|
from siteactive import is_online
|
||||||
|
|
||||||
|
|
||||||
def str2bool(value_str) -> bool:
|
def str2bool(value_str) -> bool:
|
||||||
|
@ -457,6 +458,11 @@ def _command_options() -> None:
|
||||||
dest='shared_items_federated_domains',
|
dest='shared_items_federated_domains',
|
||||||
help='Specify federation list for shared items, ' +
|
help='Specify federation list for shared items, ' +
|
||||||
'separated by spaces')
|
'separated by spaces')
|
||||||
|
parser.add_argument("--internet", "--online",
|
||||||
|
dest='online',
|
||||||
|
type=str2bool, nargs='?',
|
||||||
|
const=True, default=False,
|
||||||
|
help="Checks if internet is available")
|
||||||
parser.add_argument("--poisoned", "--poison",
|
parser.add_argument("--poisoned", "--poison",
|
||||||
dest='poisoned',
|
dest='poisoned',
|
||||||
type=str2bool, nargs='?',
|
type=str2bool, nargs='?',
|
||||||
|
@ -869,6 +875,14 @@ def _command_options() -> None:
|
||||||
|
|
||||||
argb = parser.parse_args()
|
argb = parser.parse_args()
|
||||||
|
|
||||||
|
if argb.online:
|
||||||
|
# is the internet available?
|
||||||
|
if is_online():
|
||||||
|
print("True")
|
||||||
|
else:
|
||||||
|
print("False")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if argb.poisoned:
|
if argb.poisoned:
|
||||||
# LLM poisoning example
|
# LLM poisoning example
|
||||||
base_dir = os.getcwd()
|
base_dir = os.getcwd()
|
||||||
|
|
|
@ -10,6 +10,7 @@ __module_group__ = "Core"
|
||||||
|
|
||||||
import http.client
|
import http.client
|
||||||
import ssl
|
import ssl
|
||||||
|
import socket
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from utils import data_dir
|
from utils import data_dir
|
||||||
|
|
||||||
|
@ -183,3 +184,17 @@ def load_unavailable_sites(base_dir: str) -> []:
|
||||||
print('EX: unable to read unavailable sites ' +
|
print('EX: unable to read unavailable sites ' +
|
||||||
unavailable_sites_filename)
|
unavailable_sites_filename)
|
||||||
return sites_unavailable
|
return sites_unavailable
|
||||||
|
|
||||||
|
|
||||||
|
def is_online(host: str = "8.8.8.8",
|
||||||
|
port: int = 53, timeout: int = 3) -> bool:
|
||||||
|
"""
|
||||||
|
Returns True if the internet is available
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
socket.setdefaulttimeout(timeout)
|
||||||
|
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
|
||||||
|
return True
|
||||||
|
except socket.error as ex:
|
||||||
|
print(ex)
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in New Issue