0

我正在使用 pysimpleGUI 创建一个 GUI..我想使用按钮嗅探使用 Scapy 执行 ARP 扫描,然后在 pysimpleGUI 的输出或多行元素中打印此详细信息有人可以指导我如何执行此操作

目前 ARP 扫描功能在命令行中工作,但不会在 Output 或 Multiline 元素上打印出来。

# ===================================================================================================================================
# -----------------------------------------------------------------------------------------------------------------------------------
# Import Modules Section
# -----------------------------------------------------------------------------------------------------------------------------------
import PySimpleGUI as sg
import subprocess
import os
import sys
from scapy.all import Ether, ARP, srp
from scapy.all import *

# -----------------------------------------------------------------------------------------------------------------------------------
# Define Constants Section
# -----------------------------------------------------------------------------------------------------------------------------------


sg.SetOptions(icon=None,
              button_color=('blue', 'white'),
              element_size=(None, None),
              margins=(None, None),
              element_padding=(None, None),
              auto_size_text=None,
              auto_size_buttons=None,
              font=None,
              border_width=None,
              slider_border_width=None,
              slider_relief=None,
              slider_orientation=None,
              autoclose_time=None,
              message_box_line_width=None,
              progress_meter_border_depth=None,
              progress_meter_style=None,
              progress_meter_relief=None,
              progress_meter_color=None,
              progress_meter_size=None,
              text_justification=None,
              text_color=None,
              background_color=None,
              element_background_color=None,
              text_element_background_color=None,
              input_elements_background_color=None,
              element_text_color='blue',
              input_text_color=None,
              scrollbar_color=None,
              debug_win_size=(None, None),
              window_location=(None, None),
              tooltip_time=None,
              )


# -----------------------------------------------------------------------------------------------------------------------------------
# Define Modules Section
# -----------------------------------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------------------------
# Functions
# -----------------------------------------------------------------------------------------------------------------------------------

def arp_scan():
    _range = raw_input("Enter the Target Range: ")
    _interface = raw_input("Enter the network interface: ")
    ip, ntBits = _range.split('/')
    ip_addresses = []
    st_bit = ip.split('.')[3:4][0]   #Since it's an IPv4
    for n in range(1, int(ntBits)+1):
        eval_ip = ".".join( ip.split('.')[:-1] ) + '.' + str(n)
        ip_addresses.append( eval_ip )

    for ip in ip_addresses:
        _pkt = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip)
        ans, unans = srp( _pkt, iface=_interface, timeout=0.1, verbose=False)
        for snt, recv in ans:
            if recv:
                print("Host Alive: %s - %s" % (recv[ARP].psrc, recv[Ether].src))

# -----------------------------------------------------------------------------------------------------------------------------------
# Pre-Processing Section
# -----------------------------------------------------------------------------------------------------------------------------------
joblist = []
tool = dict()
tool['input-width'] = 144
tool['input-heigt'] = 10
tool['output-width'] = 140
tool['output-heigt'] = 30
tool['output-font'] = 'Courier'
tool['output-font-size'] = 10
tool['opm-flow-manual'] = 'None'
tool['opm-resinsight'] = 'None'
tool['edit-command'] = 'None'
vers = 'v1'

# -----------------------------------------------------------------------------------------------------------------------------------
# Define GUI Section
# -----------------------------------------------------------------------------------------------------------------------------------
mainmenu = [['File', ['Open', 'Save', 'Exit']]]

flowlayout = [[sg.Output(background_color='white', text_color='black',
                         size=(tool['output-width'], tool['output-heigt']),
                         key='_outflow_', font=(tool['output-font'], tool['output-font-size']))]]

loglayout = [[sg.Multiline(background_color='white', text_color='darkgreen', do_not_clear=True,
                           key='_outlog_', size=(tool['output-width'], tool['output-heigt']),
                           font=(tool['output-font'], tool['output-font-size']))]]

mainwind = [[sg.Menu(mainmenu)],
            [sg.Text('Available Hosts')],
            [sg.Listbox(values=joblist, size=(tool['input-width'], tool['input-heigt']), key='_joblist_',
                        font=(tool['output-font'], tool['output-font-size']))],

            [sg.Button('Start', key='_start_sniff_'),
             sg.Button('Stop')],
            # sg.Button('Delete Job'),
            # sg.Button('Clear Queue', key='_clear_queue_'),
            # sg.Button('Load Queue', key='_load_queue_'),
            # sg.Button('Save Queue', key='_save_queue_')],

            [sg.TabGroup([[sg.Tab('Text', flowlayout, key='_tab_output_',
                                  title_color='black', background_color='white'),
                           sg.Tab('URL', loglayout, key='_tab_outlog_',
                                  title_color='black', background_color='white', border_width=None),
                           sg.Tab('Images', loglayout, key='_tab_outlog_',
                                  title_color='black', background_color='white', border_width=None)]],
                         title_color='black', background_color='white')],

            # [sg.Button('Run Jobs', key='_run_jobs_'),
            # sg.Button('Kill Job', key='_kill_job_'),
            # sg.Button('Clear', key='_clear_'),
            [sg.Button('Exit', key='_exit_')]]
# [sg.Text('')]]

window0 = sg.Window('CTTool - Cleartext Tool ' + vers).Layout(mainwind)
-----------------------------------------------------------------------------------------------------------------------------------
# Define GUI Event Loop, Read Buttons, and Make Callbacks etc. Section
# -----------------------------------------------------------------------------------------------------------------------------------
while True:
    #
    # Read the Form and Process and Take appropriate action based on button
    #
    button, values = window0.Read()

    if button == '_clear_':
        if '_tab_output_' in str(values):
            window0.Element('_outlog_').Update('')

    if button == '_start_sniff_':
        try:
           arp_scan()
        except:
            pass

    if button == '_exit_' or button == 'Exit' or button is None:
        text = sg.PopupYesNo('Exit CTTool?')
        if text == 'Yes':
            text = sg.PopupYesNo('Are You Sure You wish to Exit CTTool?')
            if text == 'Yes':
                break

# -----------------------------------------------------------------------------------------------------------------------------------
# Post Processing Section
# -----------------------------------------------------------------------------------------------------------------------------------
window0.Close()

# ===================================================================================================================================
# End of CTTool.py
# ===================================================================================================================================
4

1 回答 1

0

您的布局有错误。您的选项卡使用不允许的相同键。您还尝试重用一个元素。这些将生成将识别问题的弹出错误消息。 loglayout是其中之一。我复制它以解决问题。

至于集成您的arp_scan代码,您需要通过删除用户界面调用来修改它,而是将它们添加到您的主 GUI 窗口中。当您调用扫描时,传入现在通过 输入的值raw_input。还要传入您计划输出到的元素。与其使用 print,不如updateMultiline元素一起使用。

于 2020-01-28T14:17:57.753 回答