[英]How to make Python automatically allow port through Windows firewall
我有一个 FTP 服务器,我希望能够将其发送到我所在区域(不同 IP)周围的个人 Windows 10 计算机以访问文件,为了访问它们,我需要允许端口通过防火墙。 除了这样做之外,有没有办法让我的 Python 程序使用一些不需要绕过防火墙或完全绕过防火墙的其他端口?
服务器.py
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import urllib.request
import mysql.connector
sqlpass = ""
version = "1.3"
def ftp_main():
mydb = mysql.connector.connect(
host="",
port="3306",
user="",
passwd=sqlpass,
database=""
)
mycursor = mydb.cursor()
mycursor.execute("SELECT Username, Password FROM FtpInfo")
myresult = mycursor.fetchall()
Username, Password = myresult[0]
print(Username + " " + Password)
external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8')
print(external_ip)
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only
# anonymous user
authorizer.add_user(Username, Password, '.', perm='elradfmwMT')
authorizer.add_anonymous('.')
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
handler.masquerade_address = external_ip
handler.passive_ports = range(60000, 60999)
# Define a customized banner (string returned when client connects)
handler.banner = "FTP Server v" + version
address = ('', 1000)
server = FTPServer(address, handler)
# start ftp server
server.serve_forever()
ftp_main()
我不知道配置 Windows 防火墙的任何本机 Python 方式。
尽管您可以使用os.system
从 Python 简单地执行Windows netsh
命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.