pigrow_remote.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Pigrow 作者: Pragmatismo 项目源码 文件源码
def seek_for_pigrows_click(self, e):
        print("seeking for pigrows...")
        number_of_tries_per_host = 1
        pi_link_pnl.target_ip = self.tb_ip.GetValue()
        pi_link_pnl.target_user = self.tb_user.GetValue()
        pi_link_pnl.target_pass = self.tb_pass.GetValue()
        if pi_link_pnl.target_ip.split(".")[3] == '':
            pi_link_pnl.target_ip = pi_link_pnl.target_ip + '0'
        start_from = pi_link_pnl.target_ip.split(".")[3]
        lastdigits = len(str(start_from))
        hostrange = pi_link_pnl.target_ip[:-lastdigits]
        #Iterate through the ip_to_test and stop when  pigrow is found
        for ip_to_test in range(int(start_from)+1,255):
            host = hostrange + str(ip_to_test)
            pi_link_pnl.target_ip = self.tb_ip.SetValue(host)
            seek_attempt = 1
            log_on_test = False
            while True:
                print("Trying to connect to " + host)
                try:
                    ssh.connect(host, username=pi_link_pnl.target_user, password=pi_link_pnl.target_pass, timeout=3)
                    print("Connected to " + host)
                    log_on_test = True
                    box_name = self.get_box_name()
                    print("Pigrow Found; " + str(box_name))
                    self.set_link_pi_text(log_on_test, box_name)
                    return box_name #this just exits the loop
                except paramiko.AuthenticationException:
                    print("Authentication failed when connecting to " + str(host))
                except Exception as e:
                    print("Could not SSH to " + host + " because:" + str(e))
                    seek_attempt += 1
                # check if final attempt and if so stop trying
                if seek_attempt == number_of_tries_per_host + 1:
                    print("Could not connect to " + host + " Giving up")
                    break #end while loop and look at next host
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号