Título: Creando nuestro port Scanner en python! Publicado por: alearea51 en 28 Febrero 2015, 17:08 pm Hola nuevamente. En esta entrada me gustaría mostrarles como crear un scanner de puertos sencillo. Como reza el título, lo haré en Python. El código se encuentra en el libro "Violent Python" , igualmente (para el que no quiera bajarse el PDF) colocaré el enlace al script al final del artículo. Para que se entienda el funcionamiento, voy a mostrar el script por porciones e iré explicando que acciones va realizando.
Para este script usaremos las librerias "optparse" y "socket" optparse: Nos sirve para parsear opciones de línea de comando (quizás ahora suene extraño pero ya comprenderemos su funcionamiento al utilizarlo). Código: Warning! ---> Deprecated since version 2.7: The optparse module is deprecated and will not be developed further; development will continue with the argparsemodule. (no importa, sirve a nuestros fines jeje) socket: Esta librería, como se imaginarán, nos permite manejar los sockets; ponerlos a la escucha, recibir, enviar,data etc. Descripción aquí ---> http://docs.Python.org/library/socket.html En la descripción veremos todas las funciones que posee esta librería. Las que nos interesan para nuestro port scanner son las siguientes: Citar socket.gethostbyname(hostname) – This function takes a hostname such as www.google.com and returns an IPv4 address format such as 69.163.177.2. socket.gethostbyaddr(ip address) – This function takes an IPv4 address and returns a triple containing the hostname, alternative list of host names, and a list of IPv4/v6 addresses for the same interface on the host. socket.socket([family[, type[, proto]]]) – This function creates an instance of a new socket given the family. Options for the socket family are AF_INET, AF_INET6, or AF_UNIX. Additionally, the socket can be specified as SOCK_STREAM for a TCP socket or SOCK_DGRAM for a UDP socket. Finally, the protocol number is usually zero and is omitted in most cases. socket.create_connection(address[, timeout[, source_address]]) – This function takes a 2-tuple (host, port) and returns an instance of a network socket. Additionally, it has the option of taking a timeout and source address. Comenzamos.. Como mencionamos arriba, utilizaremos las librerias optparse y socket, así que a darle al import: Código Espero que sea de utilidad. Pueden ver mas en: http://mamaquieroserpentester.blogspot.com.ar/2015/02/armando-un-port-scanner-en-python.html (http://mamaquieroserpentester.blogspot.com.ar/2015/02/armando-un-port-scanner-en-python.html) Mod: al publicar posts usa las etiquetas adecuadas (code, quote, GeSHi, etc) y publicalo en la sección correcta, esto es scripting Título: Re: Creando nuestro port Scanner en python! Publicado por: engel lex en 28 Febrero 2015, 22:22 pm optparse como viste está deprecated... es mejor adaptarse que usar una función descontinuada... y en ese caso no me tomó 5 minutos hacer la traducción sin conocimientos de esa función
Código
|