Part of the code:
#-*-Coding:utf-8-*-
"""
Module implementing Portscan.
"""
From Pyqt4.qtcore import pyqtsignature
From Pyqt4.qtgui import Qdialog
From PYQT4 import Qtgui,qtcore
From Ui_portscan import Ui_portscan
Import socket
Class Portscan (Qdialog, Ui_portscan):
"""
Class documentation goes here.
"""
def __init__ (self, Parent=none):
"""
Constructor
@param parent reference to the parent widget (Qwidget)
"""
Qdialog.__init__ (self, parent)
Self.setupui (self)
# QtCore.QObject.connect (Self.pushbutton,qtcore.signal ("clicked ()"), self.on_pushbutton_clicked)
@pyqtSignature ("")
def on_pushbutton_clicked (self):
For IP in Self.getiplist ():
Self.socket_port (IP)
def getiplist (self):
self.startnum = Int (Self.ip2num (str (Self.startlineEdit.text ())))
self.endnum = Int (Self.ip2num (str (Self.endlineEdit.text ())))
IPList = []
For NUM in range (self.startnum,self.endnum+1):
IP = self.num2ip (num)
Iplist.append (IP)
Return IPList
def ip2num (SELF,IP):
IP = [INT (x) for x in Ip.split ('. ')]
return ip[0]<<24|ip[1]<<16|ip[2]<<8|ip[3]
def num2ip (Self,num):
Return '%s.%s.%s.%s '% (num & 0xff000000) >> 24,
(Num & 0x00ff0000) >> 16,
(Num & 0x0000ff00) >> 8,
Num & 0x000000ff)
def socket_port (SELF,IP):
Port = Int (Self.portlineEdit.text ())
Try
Self.messagelabel.setText (u "scanning ip:%s:%d ..."% (Ip,port))
s = Socket.socket (socket.af_inet,socket. SOCK_STREAM)
S.connect ((Ip,port))
Self.textEdit.append (' ip:%s:%d Open '% (ip,port))
Except
Self.textEdit.append (' ip:%s:%d Closed '% (ip,port))
if __name__ = = "__main__":
Import Sys
App = Qtgui.qapplication (SYS.ARGV)
UI = Portscan ()
Ui.show ()
Sys.exit (App.exec_ ())
The
also writes a pyqt4 gadget that is used primarily for learning