Exemple #1
0
def subdl(video_file_path):
    command = [
        "subdl",
        "--existing=overwrite",
        f"./{video_file_path.name}"
    ]
    execute(command, in_folder=video_file_path.parent)
    return video_file_path.parent / f"{video_file_path.stem}.srt"
 def closure():
     try:
         execute(["bash", "-c", f"netstat -tulpn | grep 'LISTEN' | grep {port}"], network_namespace=network_namespace, sudo=True)
         print("Local port is opened")
         return True
     except:
         print("Local port is closed")
         return False
Exemple #3
0
    def start(self):
        print(Fore.RED + "Starting OpenVPN... " + Style.RESET_ALL)
        config_file_path = OpenVPN.CONFIG_FOLDER_PATH / f"{self.country}.conf"
        command = [
            "openvpn",
                "--cd", str(OpenVPN.CONFIG_FOLDER_PATH),
                "--config", str(config_file_path),
                "--dev", OpenVPN.TUNNEL_NAME,
                "--errors-to-stderr"
        ]
        self.process = execute(command, sudo=True, network_namespace=self.network_namespace, background=True)

        wait_for(lambda: execute(["ip", "link", "show", OpenVPN.TUNNEL_NAME], sudo=True, network_namespace=self.network_namespace))
Exemple #4
0
 def start(self):
     print(Fore.RED + "Starting VLC... " + Style.RESET_ALL)
     self.process = execute(
         ["vlc", self.url] +
         (["--sub-file", str(self.subtitles_file_path)]
          if self.subtitles_file_path else []),
         background=True,
         network_namespace=self.network_namespace)
    def id(self):
        with ZipFile(str(self.xpi_file_path)) as zip_file:
            mozilla_rsa = zip_file.read("META-INF/mozilla.rsa")
            sh_process = execute(["sh", "-c", "openssl asn1parse -inform DER -in -  | grep -A 1 'commonName' | grep -E '{|@' | cut -d ':' -f 4"], stdin=sp.PIPE, stdout=sp.PIPE, background=True)
            sh_process.stdin.write(mozilla_rsa)
            sh_process.stdin.close()

            id = "".join(filter(lambda l: len(l) > 0, map(lambda b: b.decode("utf-8").strip(), iter(sh_process.stdout.readline, b""))))
            return id
 def list(cls, network_namespace=None):
     process = execute(["pia", "-l"], stdout=sp.PIPE, background=True)
     openvpns = []
     for line in filter(lambda line: line, map(lambda line: line.strip(), map(lambda line_in_bytes: line_in_bytes.decode("utf-8"), iter(process.stdout.readline, b"")))):
         groups = re.search("^(.*) \[nm\]$", line)
         country = None
         if groups:
             country = groups.group(1)
             openvpn = OpenVPN(network_namespace=network_namespace, country=country.replace(" ", "_"))
             openvpns.append(openvpn)
     return openvpns
    def create(self):
        print(Fore.RED + "Creating profile... " + Style.RESET_ALL)
        command = [
            "firefox", "-no-remote", "-CreateProfile",
            f"{ThrowableProfile.NAME} {self.folder_path.resolve()}"
        ]
        execute(command)

        with self.prefs_file_path.open("w") as f:
            f.write('user_pref("extensions.autoDisableScopes", 0);' + "\n")

        with self.xulstore_file_path.open("w") as f:
            f.write(
                '{"chrome://browser/content/browser.xul":{"PersonalToolbar":{"collapsed":"false"}}}'
            )

        #with (self.folder_path / "extensions.json").open("w") as f:
        #    f.write('{"addons":[{"active":true,"seen":true,"userDisabled":false,"id":"@showextip"}]}');

        return self
 def for_torrent(cls, network_namespace=None):
     print(" --> for_torrent")
     process = execute(["aria2c", CHECK_IP_MAGNET], stdout=sp.PIPE, network_namespace=network_namespace, background=True)
     for line in filter(lambda line: line, map(lambda line: line.strip(), map(lambda line_in_bytes: line_in_bytes.decode("utf-8"), iter(process.stdout.readline, b"")))):
         print(" --> line=" + line)
         groups = re.search(CHECK_IP_REGEX, line)
         ip = None
         if groups:
             ip = groups.group(0)
             break
         #else:
         #    print(line)
     kill(process, sudo=True, signal = signal.SIGKILL)
     return cls(ip)
 def start(self):
     print(Fore.RED + "Starting Peerflix... " + Style.RESET_ALL)
     self.process = execute(["peerflix", "-f", ".", "-q", ".", self.magnet], network_namespace=self.network_namespace, background=True)
     wait_for(local_port_opened(8888, network_namespace=self.network_namespace))
     print("Here we go! ")
Exemple #10
0
 def delete(self):
     print(Fore.RED + "Deleting Network Namespace... " + Style.RESET_ALL)
     execute(["ip", "link", "del", NetworkNamespace.VETH_DEFAULT], sudo=True)
     execute(["ip", "netns", "del", self.name], sudo=True)
Exemple #11
0
    def create(self):
        print(Fore.RED + "Creating Network Namespace... " + Style.RESET_ALL)
        execute(["ip", "netns", "add", self.name], sudo=True)
        mkdir(self.folder_path, sudo=True)

        # Loopback
        execute(["ip", "address", "add", "127.0.0.1/8", "dev", "lo"], sudo=True, network_namespace=self.name)
        execute(["ip", "address", "add", "::1/128", "dev", "lo"], sudo=True, network_namespace=self.name)
        execute(["ip", "link", "set", "lo", "up"], sudo=True, network_namespace=self.name)

        # Tunnel
        execute(["ip", "link", "add", NetworkNamespace.VETH_VPN, "type", "veth", "peer", "name", NetworkNamespace.VETH_DEFAULT], sudo=True)
        execute(["ip", "link", "set", NetworkNamespace.VETH_VPN, "netns", self.name], sudo=True)

        execute(["ip", "link", "set", NetworkNamespace.VETH_DEFAULT, "up"], sudo=True)
        execute(["ip", "link", "set", NetworkNamespace.VETH_VPN, "up"], sudo=True, network_namespace=self.name)

        execute(["ip", "address", "add", "10.10.10.10/31", "dev", NetworkNamespace.VETH_DEFAULT], sudo=True)
        execute(["ip", "address", "add", "10.10.10.11/31", "dev", NetworkNamespace.VETH_VPN], sudo=True, network_namespace=self.name)

        execute(["ip", "route", "add", "default", "via", "10.10.10.10", "dev", NetworkNamespace.VETH_VPN], sudo=True, network_namespace=self.name)

        execute(["sysctl", "--quiet", "net.ipv4.ip_forward=1"], sudo=True)
        execute(["iptables", "--table", "nat", "--append", "POSTROUTING", "--jump", "MASQUERADE", "--source", "10.10.10.10/31"], sudo=True)

        content = f"""nameserver 108.62.19.131
    nameserver 104.238.194
"""
        tee(content.encode("utf-8"), self.folder_path / "resolv.conf", sudo=True)
 def for_http(cls, network_namespace=None):
     process = execute(["curl", "-s", "https://api.ipify.org?format=text"], stdout=sp.PIPE, network_namespace=network_namespace, background=True)
     ip = "".join(filter(lambda line: line, map(lambda line: line.strip(), map(lambda line_in_bytes: line_in_bytes.decode("utf-8"), iter(process.stdout.readline, b"")))))
     return cls(ip)