In Dos-Box (CMD) a firewall rule can be set like this (with Administrator Privileges)
netsh advfirewall firewall add rule name="RULENAME" dir=out action=block protocol=TCP localip=any remoteip=any
netsh advfirewall firewall add rule name="RULENAME" dir=out action=allow protocol=TCP localip=any remoteip=[login to view URL]
password = "xxxxxxx"
def block_internet():
print("Call block internet")
# Block all outgoing traffic
block_cmd = '\"netsh advfirewall firewall add rule name=\"RULENAME\" dir=out action=block protocol=TCP localip=any remoteip=any\"'
[login to view URL](['runas', '/user:surface-sl-05\Administrator', 'cmd', '/c', 'echo', password, '|', 'powershell', '-Command', block_cmd], stdin=[login to view URL], stdout=[login to view URL])
print("Blocking all outgoing traffic...")
I try the same with Python but I am failing as this code is not running. For testing purposes I have saving the password in clear into the programm.
I just need the syntax for the subprocess
The code so far:
import os
import subprocess
import hashlib
import ctypes
# Funktion zum Verschlüsseln des Passworts mit MD5
def encrypt_password(password):
md5_object = [login to view URL]()
[login to view URL]([login to view URL]())
return [login to view URL]()
# Passwort im Klartext speichern
password = "Flbs28100923!"
def block_internet():
print("Call block internet")
# Block all outgoing traffic
block_cmd = '\"netsh advfirewall firewall add rule name=\"RULENAME\" dir=out action=block protocol=TCP localip=any remoteip=any\"'
[login to view URL](['runas', '/user:surface-sl-05\Administrator', 'cmd', '/c', 'echo', password, '|', 'powershell', '-Command', block_cmd], stdin=[login to view URL], stdout=[login to view URL])
print("Blocking all outgoing traffic...")
# Allow outgoing traffic to [login to view URL]
allow_cmd = 'netsh advfirewall firewall add rule name=\"Allow\" dir=out action=allow protocol=any remoteip=[login to view URL] localport=any'
[login to view URL](['runas', '/user:surface-sl-05\Administrator', 'cmd', '/c', 'echo', password, '|', 'powershell', '-Command', allow_cmd], stdin=[login to view URL], stdout=[login to view URL])
print("Allowing outgoing traffic to exam.edu.gafa.ac.at...")
# Change desktop background image
image_path = 'C:\\Program Files (x86)\\Gafa Exam\\Images\\[login to view URL]'
[login to view URL](['runas', '/user:surface-sl-05\Administrator', 'cmd', '/c', 'echo', password, '|', 'powershell', '-Command', 'REG', 'ADD', 'HKCU\\Control Panel\\Desktop', '/v', 'Wallpaper', '/t', 'REG_SZ', '/d', image_path, '/f'], stdin=[login to view URL], stdout=[login to view URL])
[login to view URL](['runas', '/user:surface-sl-05\Administrator', 'cmd', '/c', 'echo', password, '|', 'powershell', '-Command', '[login to view URL]', '[login to view URL],UpdatePerUserSystemParameters'], stdin=[login to view URL], stdout=[login to view URL])
print("Changing desktop background image...")
# Ping test
response = [login to view URL]("ping [login to view URL]")
if response == 0:
# Ping successful, display error message
[login to view URL](None, "Fehler: Ping erfolgreich, Internetverbindung nicht blockiert.", "Fehler", 0x40 | 0x1)
else:
# Ping unsuccessful, display success message
[login to view URL](None,
"Internetverbindung blockiert, nur Verbindung zu [login to view URL] ist erlaubt. Hintergrundbild wurde geändert",
"Erfolg", 0x40 | 0x1)
block_internet()