Jump to content
  • Advertisement
Sign in to follow this  
MattFrederick

[python] Having trouble getting this to work.

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whenever I test the code without the wxpython portions it works fine.


import wx
from socket import *
targetip = "0.0.0.0"

class Test(wx.Frame):
def __init__(self, *args, **kwargs):
super(Test, self).__init__(*args, **kwargs)

self.InitUI()

def InitUI(self):

panel = wx.Panel(self)
button = wx.Button(panel, label = "GetIp", pos = (50, 20), size = (60,30))
self.Bind(wx.EVT_BUTTON, self.GetIp, button)
button2 = wx.Button(panel, label = "Scan", pos = (125, 20), size = (60,30))
self.Bind(wx.EVT_BUTTON, self.Scan, button2)
menubar = wx.MenuBar()
filemenu = wx.Menu()
fitem = filemenu.Append(wx.ID_EXIT, 'Quit', 'Quit Application')
menubar.Append(filemenu, '&File')
self.SetMenuBar(menubar)

self.Bind(wx.EVT_MENU, self.OnQuit, fitem)
self.SetSize((500,400))
self.SetTitle('Simple Test')
self.Centre()
self.Show(True)

def GetIp(self, e):
box = wx.TextEntryDialog(None, "Target IP", "Enter IP", "127.0.0.1")
if box.ShowModal() == wx.ID_OK:
target = box.GetValue()
targetip = gethostbyname(target)
print targetip

def Scan(self, e):
print "Scanning IP"
for i in range(20, 1025):
s = socket(AF_INET, SOCK_STREAM)
result = s.connect_ex((targetip,i))

if(result == 0):
print "Port %d: OPEN" % (i,)
s.close()

def OnQuit(self, e):
self.Close()

def main():
ex = wx.App()
Test(None)
ex.MainLoop()

if __name__ == '__main__':
main()

Share this post


Link to post
Share on other sites
Advertisement
What does "work" mean? What is the first point at which the program's behaviour diverges from that which you expect?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!