新手小白
我在写期末作业的时候遇到了这个问题
下面是代码
import wx
import sys
import ping
import socket
from time import gmtime,strftime
def pingScan(event,results):
if hostEnd.GetValue()<hostStart.GetValue():
dlg=wx.MessageDialog(mainWin,"Invalid Local Host Selection",wx.OK|wx.ICON_EXCLAMATION)
results=dlg.ShowModal()
dlg.Destroy()
return
mainWin.StatusBar.SetStatusText('Excuting Ping Sweep....Please Wait')
utcStarrt=gmtime()
utc=strftime("%a,%d %b %Y %X +0000",utcStarrt)
results.AppendText("\n\nPing Sweep Started:"+utc+"\n\n")
baseIP=str(ipaRange.GetValue())+'.'+str(ipRange.GetValue())+'.'+str(ipcRange.GetValue())+'.'
ipRange=[]
for i in range(hostStart.GetValue(),(hostEnd.GetValue()+1)):
ipRange.append(baseIP=str(i))
for ipAddress in ipRange:
try:
mainWin.StatusBar.SetStatusText('Pinging IP:+ipAddress')
delay=ping.do_one(ipAddress,timeout=2)
results.AppendText(ipAddress+'\t')
if delay!=None:
results.AppendText('Response Success')
results.AppendText('Response Time:'+str(delay)+'Seconds')
results.AppendText("\n")
else:
results.AppendText('Response Timeout')
results.AppendText("\n")
except(socket.error,e):
results.AppendText(ipAddress)
results.AppendText('Response Failed:')
results.AppendText(e.message)
results.AppendText("\n")
utcEnd=gmtime()
utc=strftime("%a,%d %b %Y %X +0000",utcEnd)
esults.AppendText("\nPing Sweep Ended:"+utc+"\n\n")
return
def programExit(event):
sys.exit()
app=wx.App()
mainWin=wx.Frame(None,title="Simple Ping(ICMP)Sweep 1.0",size=(1200,1200))
panelAction=wx.Panel(mainWin)
scanButton=wx.Button(panelAction,label='Exit')
scanButton.Bind(wx.EVT_BUTTON,pingScan)
exitButton=wx.Button(panelAction,label='Scan')
exitButton.Bind(wx.EVT_BUTTON,pingScan)
Results=wx.TextCtrl(panelAction,style=wx.TE_MULTILINE|wx.HSCROLL)
ipaRange=wx.SpinCtrl(panelAction,-1,'')
ipaRange.SetRange(0,255)
ipaRange.SetValue(127)
ipbRange=wx.SpinCtrl(panelAction,-1,'')
ipbRange.SetRange(0,255)
ipbRange.SetValue
ipcRange=wx.SpinCtrl(panelAction, -1,'')
ipcRange.SetRange(0,255)
ipcRange.SetValue(0)
ipLabel=wx.StaticText(panelAction, label="IP Base: ")
hostStart=wx.SpinCtrl(panelAction,-1,'')
hostStart.SetRange(0,255)
hostStart.SetValue(1)
hostEnd=wx.SpinCtrl(panelAction,-1,'')
hostEnd.SetRange(0,255)
hostEnd.SetValue(10)
HostStartLabel=wx.StaticText(panelAction, label="Host Start: ")
HostEndLabel =wx.StaticText(panelAction, label="Host End: ")
actionBox=wx.BoxSizer()
actionBox.Add(scanButton,proportion=1,flag=wx.LEFT,border=5)
actionBox.Add(exitButton,proportion=0,flag=wx.LEFT,border=5)
actionBox.Add(ipLabel,proportion=0,flag=wx.LEFT,border=5)
actionBox.Add(ipaRange,proportion=0,flag=wx.LEFT,border=5)
actionBox.Add(ipbRange,proportion=0,flag=wx.LEFT,border=5)
actionBox.Add(ipcRange,proportion=0,flag=wx.LEFT,border=5)
actionBox.Add(HostStartLabel,proportion=0,flag=wx.LEFT|wx.CENTER,border=5)
actionBox.Add(hostStart,proportion=0,flag=wx.LEFT,border=5)
actionBox.Add(HostEndLabel,proportion=0,flag=wx.LEFT|wx.CENTER,border=5)
actionBox.Add(hostEnd,proportion=0,flag=wx.LEFT,border=5)
vertBox=wx.BoxSizer(wx.VERTICAL)
vertBox.Add(actionBox,proportion=0,flag=wx.EXPAND|wx.ALL,border=5)
vertBox.Add(Results,proportion=1,flag=wx.EXPAND| wx.LEFT| wx.BOTTOM | wx.RIGHT, border=5)
mainWin.CreateStatusBar()
panelAction.SetSizer(vertBox)
mainWin.Show()
app.MainLoop()