Edit key value in Windows Registry and create rule in windows firewall with Python

Asked

Viewed 47 times

-1

I need a python preject to change the port in the windows registry (HKEY_LOCAL_MACHINE System Currentcontrolset002 Control Terminal Server Winstations RDP-Tcp Portnumber) and (HKEY_LOCAL_MACHINE System Currentcontrolset001 Control Terminal Server Winstations RDP-Tcp Portnumber) and create an input and output rule for that same port in the Firewall giving permissions on the port, By not assembling the code. Could someone tell me the correct way to assemble this code? The code below is what I started with the firewall rule.However it is not creating the rule, I did several tests this was the last code I used:

import the import re import winreg

port = int(input('Enter port: ')) quotation marks = ("'")

portastr = str(port) portahera = '%x' % port release = ('netsh advfirewall firewall add Rule name="port ts server" dir=in action=allow Protocol=TCP localport=') tcp = (quotes+release+port+quotes) os.system(tcp) print(tcp)

1 answer

0

The part of the firewall consgeui resolve, I used the code below, and after compiling, I ran the exe as administrator and was ok, now missing only the part of the registry edition, need to change the port in the registry (HKEY_LOCAL_MACHINE System Currentcontrolset002 Control Terminal Server Winstations RDP-Tcp Portnumber) and (HKEY_LOCAL_MACHINE System Currentcontrolset001 Control Terminal Server Winstations RDP-Tcp Portnumber)

Follow the firewall setting code: import the import re import winreg

port = int(input('Enter port: '))

portastr = str(port) portahera = '%x' % port release = ('netsh advfirewall firewall add Rule name="port ts server" dir=in action=allow Protocol=TCP localport=') tcp = (release+portastr) os.system(tcp)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.