欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

自己亲自做的 python 判断 sftp 登录连接是否正常 有大用 有大大用

response = os.system()

response != :
    label = tk.Label(root)
    btn1 = tk.Button(root=root.destroy)
    btn1[] = root.title()
    label[] = label.place(===)
    btn1.place(===)
    root.geometry()
    root.mainloop()
    sys.exit()




ftp_2.134.py   第一版

#!/usr/bin/python3    
# 文件名:client.py    
# 导入 socket、sys 模块    
import socket
import sys
import pysftp
from paramiko.ssh_exception import AuthenticationException

host = '192.168.19.3'
port = 22    
username = 'aaaa'    
password = 'bbbb'    
# 创建 socket 对象    
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)  # 超时为4秒    
try:
    s.connect((host, port))
    msg = s.recv(64)
# s.connect(('192.168.2.134', 22))    
# 接收小于 1024 字节的数据    
except TimeoutError as err:
    print("网络不通,请联系洪守业或史平忠或李中洋")
    sys.exit(1)
else:
    print("网络是通的")
finally:
    s.close()

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
try:
    connObj = pysftp.Connection(host=host, username=username, password=password,cnopts=cnopts)
    print("用户名密码是正确的")
    connObj.close()
except AuthenticationException as err:
        print(str(err))
        print("用户名密码不对,请联系洪守业或史平忠")
except Exception as err:
        print(str(err))
        print("其它异常")


ftp_2.134.py   第二版

#!/usr/bin/python3    
# 导入 socket、sys 模块    
import socket
import sys
import pysftp
import tkinter as tk
from paramiko.ssh_exception import AuthenticationException

host = '192.168.2.134'    
port = 22

def check_account_pwd(username,password):
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None

    try:
        connObj = pysftp.Connection(host=host, username=username, password=password, cnopts=cnopts)
        print("用户名密码是正确的")
        connObj.close()
        root1 = tk.Tk()
        info_label = tk.Label(root1, text="1)用户名密码正确\n2)密码在有效期内\n3)客户端ip地址已绑定到FTP服务器")
        info_label.grid(column=0, row=1, padx=2, pady=2)
        # info_label1 = tk.Label(root1, text="1)用户名密码正确")    
        # info_label1.grid(column=0, row=1, padx=2, pady=2)    
        # info_label2 = tk.Label(root1, text="2)密码在有效期内")    
        # info_label2.grid(column=0, row=2, padx=2, pady=2)    
        # info_label3 = tk.Label(root1, text="3)客户端ip地址已绑定到FTP服务器")    
        # info_label3.grid(column=0, row=3, padx=2, pady=2)    
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('提示')
        root1.geometry("220x100")

    except AuthenticationException as err:
        print(str(err))
        print("用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系洪守业或史平忠")
        root1 = tk.Tk()
        info_label = tk.Label(root1,text="用户名密码不对\n或者密码过期\n或者客户端ip地址未绑定到FTP服务器\n请联系洪守业或史平忠")
        info_label.grid(column=0, row=1, padx=2, pady=2)
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('提示')
        root1.geometry("220x120")
    except Exception as err:
        print(str(err))
        print("用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系洪守业或史平忠")
        root1 = tk.Tk()
        info_label = tk.Label(root1,text="用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系洪守业或史平忠")
        info_label.grid(column=0, row=1, padx=2, pady=2)
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('提示')
        root1.geometry("220x120")
 
def account_pwd_values():
        # 获取Entry小部件中的文本值    
        account = account_entry.get()
        pwd = pwd_entry.get()
        root.destroy()
        check_account_pwd(account,pwd)

root = tk.Tk()
label = tk.Label(root)
btn1 = tk.Button(root, command=root.destroy)
btn1["text"] = "确定"    
root.title('提示')

# server = '192.168.19.3'    
# 创建 socket 对象    
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)  # 超时为4秒    
try:
    s.connect((host, port))    
    msg = s.recv(64)
# s.connect(('192.168.2.134', 22))    
# 接收小于 1024 字节的数据    
except TimeoutError as err:
    label["text"]='网络不通,请联系洪守业或史平忠'    
    label.place(x=100, y=50, anchor='s')
    btn1.place(x=100, y=90, anchor='s')
    root.geometry("200x100")
    root.mainloop()
    sys.exit()
else:
    print("网络是通的")
finally:
    s.close()
# 创建第一个输入框    
account_label = tk.Label(root, text="帐号:")
account_label.grid(column=0,row=0,padx=2,pady=2)
account_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
account_entry.grid(column=1,row=0,columnspan=2,padx=2,pady=2)

# 创建第二个输入框    
pwd_label = tk.Label(root, text="密码:")
pwd_label.grid(column=0,row=1,padx=2,pady=2)
pwd_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
pwd_entry.grid(column=1,row=1,columnspan=2,padx=2,pady=2)

# 创建一个按钮,并绑定事件处理函数    
button = tk.Button(root, text="确定", command=account_pwd_values)
button.grid(column=1,row=2,columnspan=2,padx=2,pady=2)
root.geometry("220x100")
# 运行窗口的主循环    
root.mainloop()



ftp_2.134.py   第三版

#!/usr/bin/python3    
# 导入 socket、sys 模块    
import subprocess
import socket
import sys
import pysftp
import tkinter as tk
from paramiko.ssh_exception import AuthenticationException

host = '192.168.2.134'    
port = 22
   
def check_account_pwd(username,password):
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None    
    try:
        connObj = pysftp.Connection(host=host, username=username, password=password, cnopts=cnopts)
        print("用户名密码是正确的")
        connObj.close()
        root1 = tk.Tk()
        info_label = tk.Label(root1, text="1)用户名密码正确\n2)密码在有效期内\n3)客户端ip地址已绑定到FTP服务器")
        info_label.grid(column=0, row=1, padx=2, pady=2)
        # info_label1 = tk.Label(root1, text="1)用户名密码正确")    
        # info_label1.grid(column=0, row=1, padx=2, pady=2)    
        # info_label2 = tk.Label(root1, text="2)密码在有效期内")    
        # info_label2.grid(column=0, row=2, padx=2, pady=2)    
        # info_label3 = tk.Label(root1, text="3)客户端ip地址已绑定到FTP服务器")    
        # info_label3.grid(column=0, row=3, padx=2, pady=2)    
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('提示')
        root1.geometry("220x100")

    except AuthenticationException as err:
        print(str(err))
        print("用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系洪守业或史平忠")
        root1 = tk.Tk()
        info_label = tk.Label(root1,text="用户名密码不对\n或者密码过期\n或者客户端ip地址未绑定到FTP服务器\n请联系洪守业或史平忠")
        info_label.grid(column=0, row=1, padx=2, pady=2)
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('提示')
        root1.geometry("220x120")
    except Exception as err:
        print(str(err))
        print("用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系洪守业或史平忠")
        root1 = tk.Tk()
        info_label = tk.Label(root1,text="用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系洪守业或史平忠")
        info_label.grid(column=0, row=1, padx=2, pady=2)
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('提示')
        root1.geometry("220x120")
 
def account_pwd_values():
        # 获取Entry小部件中的文本值    
        account = account_entry.get()
        pwd = pwd_entry.get()
        root.destroy()
        check_account_pwd(account,pwd)

root = tk.Tk()
label = tk.Label(root)
btn1 = tk.Button(root, command=root.destroy)
btn1["text"] = "确定"    
root.title('提示')
   
command  = 'ping -w 1000 192.168.2.2'    
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
 
if process.returncode != 0:
    label["text"] = '没有网络,请检查!'    
    label.place(x=100, y=50, anchor='s')
    btn1.place(x=100, y=90, anchor='s')
    root.geometry("200x100")
    root.mainloop()
    sys.exit()

# 创建 socket 对象    
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)  # 超时为4秒    
try:

    s.connect((host, port))
    msg = s.recv(64)
# s.connect(('192.168.2.134', 22))    
# 接收小于 1024 字节的数据    
except TimeoutError as err:
    label["text"]='到FTP服务器网络不通,请联系洪守业或史平忠'    
    label.place(x=125, y=50, anchor='s')
    btn1.place(x=125, y=90, anchor='s')
    root.geometry("250x100")
    root.mainloop()
    sys.exit()
else:
    print("到FTP服务器网络是通的")
finally:
    s.close()
# 创建第一个输入框    
account_label = tk.Label(root, text="帐号:")
account_label.grid(column=0,row=0,padx=2,pady=2)
account_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
account_entry.grid(column=1,row=0,columnspan=2,padx=2,pady=2)
   
# 创建第二个输入框    
pwd_label = tk.Label(root, text="密码:")
pwd_label.grid(column=0,row=1,padx=2,pady=2)
pwd_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
pwd_entry.grid(column=1,row=1,columnspan=2,padx=2,pady=2)

# 创建一个按钮,并绑定事件处理函数    
button = tk.Button(root, text="确定", command=account_pwd_values)
button.grid(column=1,row=2,columnspan=2,padx=2,pady=2)
root.geometry("220x100")
# 运行窗口的主循环    
root.mainloop()


ftp_2.134_22.py   第四版

#!/usr/bin/python3    
import os
import subprocess
import socket
import sys
import pysftp
import tkinter as tk
from paramiko.ssh_exception import AuthenticationException

host = '192.168.2.134'    
port = 22    
# 执行ipconfig命令    
local_ip = os.popen('ipconfig | findstr /I "IPv4" | find " 10." ').read()
local_ip = local_ip.replace(" ",'')

local_ip = local_ip.replace("...",'')

local_ip = "本机"+local_ip

def ftp_auth_error(err):
    print(str(err))
    print("用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系洪守业或史平忠")
    root1 = tk.Tk()
    info_label0 = tk.Label(root1, text=local_ip)
    info_label0.grid(column=0, row=1, padx=2, pady=2)
    info_label1 = tk.Label(root1,text="用户名密码不对\n或者密码过期\n或者客户端ip地址未绑定到FTP服务器\n请联系洪守业或史平忠")
    info_label1.grid(column=0, row=2, padx=2, pady=2)
    btn1 = tk.Button(root1, command=root1.destroy)
    btn1.grid(column=0, row=5, padx=2, pady=2)
    btn1["text"] = "确定"    
    root1.title('FTP 帐号密码')
    #root1.geometry("210x160")#不能设宽度,才能居中    
def check_account_pwd(username,password):
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None    
    try:
        connObj = pysftp.Connection(host=host, username=username, password=password, cnopts=cnopts)
        print("用户名密码是正确的")
        connObj.close()
        root1 = tk.Tk()
        info_label0 = tk.Label(root1, text=local_ip)
        info_label0.grid(column=0, row=1, padx=2, pady=2)
        info_label1 = tk.Label(root1, text="1)用户名密码正确\n2)密码在有效期内\n3)客户端ip地址已绑定到FTP服务器")
        info_label1.grid(column=0, row=2, padx=2, pady=2)
        # info_label1 = tk.Label(root1, text="1)用户名密码正确")    
        # info_label1.grid(column=0, row=1, padx=2, pady=2)    
        # info_label2 = tk.Label(root1, text="2)密码在有效期内")    
        # info_label2.grid(column=0, row=2, padx=2, pady=2)    
        # info_label3 = tk.Label(root1, text="3)客户端ip地址已绑定到FTP服务器")    
        # info_label3.grid(column=0, row=3, padx=2, pady=2)    
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('FTP 帐号密码')
        #root1.geometry("210x150") #不能设宽度,才能居中
    except AuthenticationException as err:
        ftp_auth_error(err)

    except Exception as err:
        ftp_auth_error(err)

def account_pwd_values():
        # 获取Entry小部件中的文本值    
        account = account_entry.get()
        pwd = pwd_entry.get()
        root.destroy()
        check_account_pwd(account,pwd)

def to_ftp_net_error():
    info_label0 = tk.Label(root, text=local_ip)
    info_label0.grid(column=0, row=1, padx=2, pady=2)
    label = tk.Label(root)
    btn1 = tk.Button(root, command=root.destroy)
    btn1["text"] = "确定"    
    root.title('提示')
    label["text"] = '到FTP服务器网络不通,请联系洪守业或史平忠'    
    label.place(x=125, y=50, anchor='s')
    btn1.place(x=125, y=90, anchor='s')
    root.title('FTP 帐号密码')
    root.geometry("250x100")
    root.mainloop()
    sys.exit()

root = tk.Tk() 
command  = 'ping -n 1 -w 1000 192.168.2.2'    
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()

if process.returncode != 0:
    label = tk.Label(root)
    btn1 = tk.Button(root, command=root.destroy)
    btn1["text"] = "确定"    
    root.title('提示')
    label["text"] = '没有网络,请检查!'    
    label.place(x=100, y=50, anchor='s')
    btn1.place(x=100, y=90, anchor='s')
    root.geometry("250x100")
    root.title('FTP 帐号密码')
    root.mainloop()
    sys.exit()

# 创建 socket 对象    
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)  # 超时为4秒    
try:
    s.connect((host, port))
    msg = s.recv(64)
# s.connect(('192.168.2.134', 22))    
# 接收小于 1024 字节的数据    
except TimeoutError as err:
    to_ftp_net_error()
except Exception as err:
    to_ftp_net_error()
else:
    print("到FTP服务器网络是通的")
finally:
    s.close()
# 创建第一个输入框    
account_label = tk.Label(root, text="FTP 帐号:")
account_label.grid(column=0,row=0,padx=2,pady=2)
account_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
account_entry.grid(column=1,row=0,columnspan=2,padx=2,pady=2)

# 创建第二个输入框    
pwd_label = tk.Label(root, text="FTP 密码:")
pwd_label.grid(column=0,row=1,padx=2,pady=2)
pwd_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
pwd_entry.grid(column=1,row=1,columnspan=2,padx=2,pady=2)

# 创建一个按钮,并绑定事件处理函数    
button = tk.Button(root, text="确定", command=account_pwd_values)
button.grid(column=1,row=2,columnspan=2,padx=2,pady=2)
root.title('FTP 帐号密码')

root.geometry("250x100")

# 运行窗口的主循环

   
root.mainloop()



sftp_2.134_22.py   第五版

#!/usr/bin/python3    
from ping3 import ping, verbose_ping
import socket
import sys
import pysftp
import tkinter as tk
from paramiko.ssh_exception import AuthenticationException

host = '192.168.2.134'    
port = 22 
   
def net_connection_err():
    label = tk.Label(root)
    btn1 = tk.Button(root, command=root.destroy)
    btn1["text"] = "确定"    
    root.title('提示')
    label["text"] = '这个电脑没有网络,请检查!'    
    label.grid(column=0, row=1, padx=10, pady=2)
    btn1.grid(column=0, row=2, padx=10, pady=2)
    # root.geometry("250x100") #为了居中,最好不要设定宽度和高度吧    
    root.title('FTP 帐号密码')
    root.mainloop()
    sys.exit()    
root = tk.Tk()
try:
    latency = ping('192.168.2.2')  # 获取延迟时间,单位为微秒    
    if latency is None or  latency == False  :
    net_connection_err()
except Exception as err:
    net_connection_err()
print(latency)

#得到本地ip    
def get_local_ip():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(('192.168.2.2', 80))
    local_ip = s.getsockname()[0]
    s.close()
    return local_ip
   
local_ip = "本机 ip "+get_local_ip()
   
def ftp_auth_error(err):
    print(str(err))
    print("用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系 JS-ES.Security@luxshare-ict.com")
    root1 = tk.Tk()
    info_label0 = tk.Label(root1, text=local_ip)
    info_label0.grid(column=0, row=1, padx=2, pady=2)
    info_label1 = tk.Label(root1,text="用户名密码不对\n或者密码过期\n或者客户端ip地址未绑定到FTP服务器\n请联系 JS-ES.Security@luxshare-ict.com")
    info_label1.grid(column=0, row=2, padx=2, pady=2)
    btn1 = tk.Button(root1, command=root1.destroy)
    btn1.grid(column=0, row=5, padx=2, pady=2)
    btn1["text"] = "确定"    
    root1.title('FTP 帐号密码')
    #root1.geometry("210x160")#不能设宽度,才能居中    
def check_account_pwd(username,password):
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None    
    try:
        connObj = pysftp.Connection(host=host, username=username, password=password, cnopts=cnopts)
        print("用户名密码是正确的")
        connObj.close()
        root1 = tk.Tk()
        info_label0 = tk.Label(root1, text=local_ip)
        info_label0.grid(column=0, row=1, padx=2, pady=2)
        info_label1 = tk.Label(root1, text="1)用户名密码正确\n2)密码在有效期内\n3)客户端ip地址已绑定到FTP服务器")
        info_label1.grid(column=0, row=2, padx=2, pady=2)
        # info_label1 = tk.Label(root1, text="1)用户名密码正确")    
        # info_label1.grid(column=0, row=1, padx=2, pady=2)    
        # info_label2 = tk.Label(root1, text="2)密码在有效期内")    
        # info_label2.grid(column=0, row=2, padx=2, pady=2)    
        # info_label3 = tk.Label(root1, text="3)客户端ip地址已绑定到FTP服务器")    
        # info_label3.grid(column=0, row=3, padx=2, pady=2)    
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('FTP 帐号密码')
        #root1.geometry("210x150") #不能设宽度,才能居中    
    except AuthenticationException as err:
        ftp_auth_error(err)

    except Exception as err:
        ftp_auth_error(err)

def account_pwd_values():
        # 获取Entry小部件中的文本值    
        account = account_entry.get()
        pwd = pwd_entry.get()
        root.destroy()
        check_account_pwd(account,pwd)

def to_ftp_net_error():
    info_label0 = tk.Label(root, text=local_ip)
    info_label0.grid(column=0, row=1, padx=2, pady=2)
    label = tk.Label(root)
    btn1 = tk.Button(root, command=root.destroy)
    btn1["text"] = "确定"    
    root.title('提示')
    label["text"] = '到FTP服务器网络不通,请联系 JS-ES.Security@luxshare-ict.com'    
    label.grid(column=0, row=2, padx=10, pady=2)
    btn1.grid(column=0, row=3, padx=10, pady=2)
    root.title('FTP 帐号密码')
    #root.geometry("250x100")   #不能设宽度,才能居中    
    root.mainloop()
    sys.exit()
   
# 创建 socket 对象    
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)  # 超时为4秒    
try:
    s.connect((host, port))
    msg = s.recv(64)
# s.connect(('192.168.2.134', 22))    
# 接收小于 1024 字节的数据    
except TimeoutError as err:
    to_ftp_net_error()
except Exception as err:
    to_ftp_net_error()
else:
    print("到FTP服务器的网络是通的")
finally:
    s.close()
# 创建第一个输入框    
account_label = tk.Label(root, text="FTP 帐号:")
account_label.grid(column=0,row=0,padx=2,pady=2)
account_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
account_entry.grid(column=1,row=0,columnspan=2,padx=2,pady=2)

# 创建第二个输入框    
pwd_label = tk.Label(root, text="FTP 密码:")
pwd_label.grid(column=0,row=1,padx=2,pady=2)
pwd_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
pwd_entry.grid(column=1,row=1,columnspan=2,padx=2,pady=2)

# 创建一个按钮,并绑定事件处理函数    
button = tk.Button(root, text="确定", command=account_pwd_values)
button.grid(column=1,row=2,columnspan=2,padx=2,pady=2)
root.title('FTP 帐号密码')
root.geometry("250x100")
# 运行窗口的主循环    
root.mainloop()



sftp_ftp02.luxshare-ict.com_222.py   第五版

#!/usr/bin/python3    
import os
import subprocess
from ping3 import ping, verbose_ping
import requests
import socket
import sys
import pysftp
import tkinter as tk
from paramiko.ssh_exception import AuthenticationException
 
host = 'ftp02.luxshare-ict.com'    
port = 222  
def net_connection_err():
    label = tk.Label(root)
    btn1 = tk.Button(root, command=root.destroy)
    btn1["text"] = "确定"    
    root.title('提示')
    label["text"] = '这个电脑没有网络,请检查!'    
    label.grid(column=0, row=1, padx=10, pady=2)
    btn1.grid(column=0, row=2, padx=10, pady=2)
    # root.geometry("250x100") #为了居中,最好不要设定宽度和高度吧    
    root.title('FTP 帐号密码')
    root.mainloop()
    sys.exit()
 
root = tk.Tk()
try:
    latency = ping('www.baidu.com')  # 获取延迟时间,单位为微秒    
    if latency is None or latency == False:
        net_connection_err()
except Exception as err:
    net_connection_err()
print(latency)
 
#得到公网ip    
def get_public_ip():
    response = requests.get('https://ipinfo.io/json')
    ip = response.json().get('ip')
    return ip

local_ip = "本机公网ip "+get_public_ip()
   
def ftp_auth_error(err):
    print(str(err))
    print("用户名密码不对,或者密码过期,或者客户端ip地址未绑定到FTP服务器,请联系 JS-ES.Security@luxshare-ict.com")
    root1 = tk.Tk()
    info_label0 = tk.Label(root1, text=local_ip)
    info_label0.grid(column=0, row=1, padx=2, pady=2)
    info_label1 = tk.Label(root1,text="用户名密码不对\n或者密码过期\n或者客户端ip地址未绑定到FTP服务器\n请联系 JS-ES.Security@luxshare-ict.com")
    info_label1.grid(column=0, row=2, padx=2, pady=2)
    btn1 = tk.Button(root1, command=root1.destroy)
    btn1.grid(column=0, row=5, padx=2, pady=2)
    btn1["text"] = "确定"    
    root1.title('FTP 帐号密码')
    #root1.geometry("210x160")#不能设宽度,才能居中    
def check_account_pwd(username,password):
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None    
    try:
        connObj = pysftp.Connection(host=host, username=username, password=password, cnopts=cnopts)
        print("用户名密码是正确的")
        connObj.close()
        root1 = tk.Tk()
        info_label0 = tk.Label(root1, text=local_ip)
        info_label0.grid(column=0, row=1, padx=2, pady=2)
        info_label1 = tk.Label(root1, text="1)用户名密码正确\n2)密码在有效期内\n3)客户端ip地址已绑定到FTP服务器")
        info_label1.grid(column=0, row=2, padx=2, pady=2)
        # info_label1 = tk.Label(root1, text="1)用户名密码正确")    
        # info_label1.grid(column=0, row=1, padx=2, pady=2)    
        # info_label2 = tk.Label(root1, text="2)密码在有效期内")    
        # info_label2.grid(column=0, row=2, padx=2, pady=2)    
        # info_label3 = tk.Label(root1, text="3)客户端ip地址已绑定到FTP服务器")    
        # info_label3.grid(column=0, row=3, padx=2, pady=2)    
        btn1 = tk.Button(root1, command=root1.destroy)
        btn1.grid(column=0, row=5, padx=2, pady=2)
        btn1["text"] = "确定"    
        root1.title('FTP 帐号密码')
        #root1.geometry("210x150") #不能设宽度,才能居中      
    except AuthenticationException as err:
        ftp_auth_error(err)
 
    except Exception as err:
        ftp_auth_error(err)

def account_pwd_values():
        # 获取Entry小部件中的文本值    
        account = account_entry.get()
        pwd = pwd_entry.get()
        root.destroy()

        check_account_pwd(account,pwd)


def to_ftp_net_error():
    info_label0 = tk.Label(root, text=local_ip)
    info_label0.grid(column=0, row=1, padx=2, pady=2)
    label = tk.Label(root)
    btn1 = tk.Button(root, command=root.destroy)
    btn1["text"] = "确定"    
    root.title('提示')
    label["text"] = '到FTP服务器网络不通,请联系  JS-ES.Security@luxshare-ict.com'    
    label.grid(column=0, row=2, padx=10, pady=2)
    btn1.grid(column=0, row=3, padx=10, pady=2)
    root.title('FTP 帐号密码')
    #root.geometry("250x100") #不能设宽度,才能居中    
    root.mainloop()
    sys.exit()
 
# 创建 socket 对象    
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)  # 超时为4秒    
try:  
    s.connect((host, port))
    msg = s.recv(64)
# s.connect(('192.168.2.134', 22))    
# 接收小于 1024 字节的数据    
except TimeoutError as err:
    to_ftp_net_error()
except Exception as err:
    to_ftp_net_error()
else:
    print("到FTP服务器网络是通的")
finally:
    s.close()
# 创建第一个输入框    
account_label = tk.Label(root, text="FTP 帐号:")
account_label.grid(column=0,row=0,padx=2,pady=2)
account_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
account_entry.grid(column=1,row=0,columnspan=2,padx=2,pady=2)
   
# 创建第二个输入框    
pwd_label = tk.Label(root, text="FTP 密码:")
pwd_label.grid(column=0,row=1,padx=2,pady=2)
pwd_entry = tk.Entry(root,bd=1,relief=tk.SOLID)
pwd_entry.grid(column=1,row=1,columnspan=2,padx=2,pady=2)
   
# 创建一个按钮,并绑定事件处理函数    
button = tk.Button(root, text="确定", command=account_pwd_values)
button.grid(column=1,row=2,columnspan=2,padx=2,pady=2)
root.title('FTP 帐号密码')
root.geometry("250x100")
# 运行窗口的主循环    
root.mainloop()





普通分类: