Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tftp_server_for_ever(port, tftp_server_dir):
ip_address = socket.gethostbyname(socket.getfqdn())
server = tftpy.TftpServer(tftp_server_dir)
server.listen(ip_address, port)
def tftp_server_for_ever(port, tftp_server_dir):
ip_address = socket.gethostbyname(socket.getfqdn())
server = tftpy.TftpServer(tftp_server_dir)
server.listen(ip_address, port)
def __init__(self, listen, handler=None):
(ip, port) = listen
self.ip = ip
self.port = port
TftpServer.__init__(self, tftproot='./')
def tftp_server_for_ever(port, tftp_server_dir):
ip_address = socket.gethostbyname(socket.getfqdn())
server = tftpy.TftpServer(tftp_server_dir)
# log_level = logging.DEBUG
log_level = logging.WARNING
log = logging.getLogger('tftpy')
log.setLevel(log_level)
server.listen(ip_address, port, timeout=20)
f = tempfile.TemporaryFile()
if file_to_transfer.lower().endswith("-confg"):
log("Generating config for", raddress,"config =", switch)
if generate(f, raddress, switch) == None:
return None
else:
error("Switch", raddress, "config =", switch, "tried to get file",
file_to_transfer)
f.close()
return None
f.seek(0)
return f
log("swtftpd started")
server = tftpy.TftpServer('/srv/tftp', file_callback)
tftplog = logging.getLogger('tftpy.TftpClient')
tftplog.setLevel(logging.WARN)
try:
server.listen("192.168.40.10", 69)
except tftpy.TftpException as err:
sys.stderr.write("%s\n" % str(err))
sys.exit(1)
except KeyboardInterrupt:
sys.stderr.write("\n")
help='upgrade logging from info to debug')
options, args = parser.parse_args()
if options.debug:
log.setLevel(logging.DEBUG)
# increase the verbosity of the formatter
debug_formatter = logging.Formatter('[%(asctime)s%(msecs)03d] %(levelname)s [%(name)s:%(lineno)s] %(message)s')
handler.setFormatter(debug_formatter)
elif options.quiet:
log.setLevel(logging.WARN)
if not options.root:
parser.print_help()
sys.exit(1)
server = tftpy.TftpServer(options.root)
try:
server.listen(options.ip, options.port)
except tftpy.TftpException as err:
sys.stderr.write("%s\n" % str(err))
sys.exit(1)
except KeyboardInterrupt:
pass
def start_tftp():
tftpy.setLogLevel(logging.DEBUG)
server = tftpy.TftpServer("/", dyn_file_func=interceptor)
server.listen(listenip="", listenport=69)
global tftpy
import tftpy
try:
tftpy.TftpContextServer.start = start # Overwrite the function
tftpy.TftpContextServer.end = end # Overwrite the function
tftpy.TftpStateExpectACK.sendDAT = sendDAT
except NameError:
pass
log("start_tftp: Starting Up TFTPy")
#tftpy.setLogLevel(logging.DEBUG)
try:
server = tftpy.TftpServer(config.running["tftproot"], dyn_file_func=interceptor)
except tftpy.TftpShared.TftpException:
log("start_tftp: ERROR: TFTP Root path doesn't exist. Creating...")
os.system('mkdir -p ' + config.running["tftproot"])
server = tftpy.TftpServer(config.running["tftproot"], dyn_file_func=interceptor)
server.listen(listenip="", listenport=69)
log("start_tftp: Started up successfully")
def startTftpServer(tftpRoot):
#create TFTP server using defined directory for target
global globalError
global tftpServer
if not os.path.exists(tftpRoot):
os.makedirs(tftpRoot)
try:
tftpServer = tftpy.TftpServer(tftpRoot)
tftpServer.listen('0.0.0.0', 69)
except Exception, e:
print "\nError starting TFTP server (maybe another instance is running?)"
print "\nError message is: " + str(e)
globalError = True