![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Apr 2009
Posts: 3
OS: Windows 7 (Build 7000)
|
I started to learn python a few weeks ago and thought a port scanner would be a great way to learn a new language (string manip., networking, variables).
I even created a GUI for it using Tkinter, but I have two main problems: 1. The port scanner (Before I created the GUI) scanned until it found one open port, was supposed to close it, and the scan further. But, once it found an open port, it just flew through the others without scanning them, only displaying that it was trying to connect and went on to the next port. ![]() 2. Finding the first problem (Not being able to solve it), I decided to try tkinter. It all worked until I needed to get the IP to scan from the user through a text box. After creating the text box and retrieving the IP from it, there always seems to be a new line string after it?! This does not happen with the text boxes for the port to start and end.Here is the full code of the port scanner as it is: Code:
import socket
import Tkinter
print 'Modules Imported.'
win = Tkinter.Tk()
win.title('Port Scanner by Ianvdl')
win.geometry('400x180')
print 'Window Done.'
IP_Input = Tkinter.Text(win)
IP_Input.pack(expand=Tkinter.YES, fill=Tkinter.NONE)
IP_Input.place_configure(width=120, height=20)
IP_Input.place_configure(x=40, y=10)
print 'IP_Input Done.'
PortS = Tkinter.Text(win)
PortS.pack(expand=Tkinter.YES, fill=Tkinter.NONE)
PortS.place_configure(width=80, height=20)
PortS.place_configure(x=40, y=35)
print 'PortStart Done.'
PortE = Tkinter.Text(win)
PortE.pack(expand=Tkinter.YES, fill=Tkinter.NONE)
PortE.place_configure(width=80, height=20)
PortE.place_configure(x=40, y=60)
print 'PortEnd Done.'
ScanButton = Tkinter.Button(win, text='Scan')
ScanButton.pack(expand=Tkinter.YES, fill=Tkinter.NONE)
ScanButton.place_configure(x=10, y=150)
ScanButton.place_configure(width=120, height=20)
print 'Scanbutton Done.'
Label1 = Tkinter.Label(win, text='Percentage Done: Not Started.')
Label1.pack(expand=Tkinter.YES, fill=Tkinter.NONE)
Label1.place_configure(x=10, y=95)
Label1.place_configure(width=200, height=20)
print 'Label1 Done.'
IP_Input.insert(0.0, '127.0.0.1')
print IP_Input.get(0.0, Tkinter.END) #Debugging
PortS.insert(0.0, '1')
PortE.insert(0.0, '65000')
print 'Load Done.'
IP_Input.focus()
################################################################
def Scan():
print 'Scan Called.' #Debugging
IP = str(IP_Input.get(0.0, Tkinter.END))
print IP #Debugging
Start = int(PortS.get(0.0, Tkinter.END))
End = int(PortE.get(0.0, Tkinter.END))
TestSocket = socket.socket()
CurrentPort = Start
OpenPorts = 0
print 'Starting scan...'
HowFar = int(CurrentPort/End * 100)
ProgText = HowFar, r'%'
Label1.config(text=('Percentage Done:', ProgText))
while CurrentPort <= int(End):
print 'Attempting Connection at:', IP, ':', CurrentPort
print IP #Debugging
print CurrentPort #Debugging
try:
TestSocket.connect((str(IP), CurrentPort)) #Test the connection
print 'Open at:', IP, ':', CurrentPort
TestSocket.close()
print 'Closed the connection.'
CurrentPort += 1
OpenPorts += 1
except:
CurrentPort += 1
finally:
HowFar = int(CurrentPort/End * 100)
ProgText = HowFar, r'%'
Label1.config(text=ProgText)
else:
print 'Scan completed from port:', Start, 'to port', End
print 'Amount of Ports open:', OpenPorts
HowFar = int(CurrentPort/End * 100)
ProgText = HowFar, r'%'
Label1.config(text=ProgText)
################################################################
ScanButton = Tkinter.Button(win, text='Scan', command=Scan)
ScanButton.pack(expand=Tkinter.YES, fill=Tkinter.NONE)
ScanButton.place_configure(x=10, y=150)
ScanButton.place_configure(width=120, height=20)
Tkinter.mainloop()
Any help will be appreciated.
|
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Tech, Networking Forums
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,142
OS: All of the above
|
Re: Help with Python Port Scanner Please
The best port scanner in the world I believe was written in Python. NMAP. You can download the program and I believe it comes with the source code.
|
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Apr 2009
Posts: 3
OS: Windows 7 (Build 7000)
|
Re: Help with Python Port Scanner Please
Thank you for the reply.
I have heard of NMAP before, but I think it might be a little difficult to master the source code. But I'll check it out anyway. ;D |
|
|
|
|
|
#4 (permalink) |
|
Registered User
Join Date: Apr 2009
Posts: 3
OS: Windows 7 (Build 7000)
|
Re: Help with Python Port Scanner Please
Thank you for the reply.
I have heard of NMAP before, but I think it might be a little difficult to master the source code. But I'll check it out anyway. ;D |
|
|
|
![]() |
| Thread Tools | |
|
|