我有一个FTP服务器,我希望能够发送到我的区域(不同的IP)周围的个人Windows 10计算机访问文件,并且为了访问它们,我需要允许端口通过防火墙。而不是这样做,有没有办法让我的Python程序使用一些不需要绕过防火墙的其他端口或完全绕过防火墙?
server.朋友
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()
我不知道任何本机Python方式配置Windows防火墙。
虽然你可以使用Windows netsh
command从Python执行os.system
。