Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: 0x5d en 31 Octubre 2013, 04:59 am



Título: [Código-PyQT4] Escaner de Puertos - JaAViEr | 0x5d
Publicado por: 0x5d en 31 Octubre 2013, 04:59 am
Hola !

Luego de meses o quizás año sin tocar la librería QT4 de Python, hoy me quise re-encantar con dicha lib. Ya se me olvidó todo, a tal punto que tuve que re-leer el mismo tutorial que hice hace un tiempo, pero viendo algunos códigos viejos que hice, ya recordé algo :P...

(...) Sin embargo no traigo un graaaaaan código, solo es un Escaner de puertos, con algo de CSS :
(http://oi39.tinypic.com/b3lvec.jpg)
Código
  1. # -*- coding: utf-8 -*-
  2. # self.setGeometry(X, Y, Width, Height)
  3.  
  4. from PyQt4 import QtGui, QtCore
  5. import sys
  6. import httplib
  7.  
  8. class programa(QtGui.QWidget):
  9.  
  10. def __init__(self, parent=None):
  11.  
  12. QtGui.QWidget.__init__(self, parent)
  13. self.setFixedSize(230, 110)
  14. self.setWindowTitle("Escaner de Puertos")
  15. self.setStyleSheet("background: #000;")
  16. # URL , LABEL URL
  17. self.url = QtGui.QLineEdit(self)
  18. self.url.setGeometry(27, 10, 200, 20)
  19. self.url.setStyleSheet("color: #fff; background: #000;")
  20. self.url_label = QtGui.QLabel("URL:", self)
  21. self.url_label.setStyleSheet("color: #fff;")
  22. self.url_label.setGeometry(3, 10, 25, 20)
  23. # PUERTO, LABEL PUERTO
  24. self.puerto = QtGui.QLineEdit(self)
  25. self.puerto.setGeometry(41, 35, 40, 20)
  26. self.puerto.setStyleSheet("color: #fff; font-weight: bold; background: #000;")
  27. self.puerto_label = QtGui.QLabel("Puerto:", self)
  28. self.puerto_label.setStyleSheet("color: #fff;")
  29. self.puerto_label.setGeometry(3, 36, 35, 20)
  30. # STATUS, LABEL STATUS
  31. self.status_label = QtGui.QLabel("Estado:", self)
  32. self.status_label.setStyleSheet("color: #fff;")
  33. self.status_label.setGeometry(3, 60, 50, 20)
  34. self.esperando = QtGui.QLabel("Esperando", self)
  35. self.esperando.setStyleSheet("color: red; font-weight: bold; background: #000;");
  36. self.esperando.setGeometry(44, 60, 100, 20)
  37. # BOTON
  38. self.boton = QtGui.QPushButton("Scan!", self)
  39. self.boton.setStyleSheet("color: #fff; background: #000; border: 2px solid #fff;")
  40. self.boton.setGeometry(3, 85, 225, 20)
  41. self.connect(self.boton, QtCore.SIGNAL("clicked()"), self.scan)
  42.  
  43. def scan(self):
  44. url = str(self.url.text())
  45. puerto = int(self.puerto.text())
  46. try:
  47. conn = httplib.HTTPConnection(url, puerto, timeout=2)
  48. BODY = "***filecontents***"
  49. conn.request("GET", "/", BODY)
  50. resp = conn.getresponse()
  51. if resp.status == 200:
  52. self.esperando.setStyleSheet("color: green; font-weight: bold")
  53. self.esperando.setText("%s Abierto" % puerto)
  54. conn.close()
  55. except:
  56. self.esperando.setStyleSheet("color: red; font-weight: bold")
  57. self.esperando.setText("%s Cerrado" % puerto)
  58. app = QtGui.QApplication(sys.argv)
  59. form = programa()
  60. form.show()
  61. app.exec_()
  62.  

Saludos !