{"id":187,"date":"2015-02-01T16:11:31","date_gmt":"2015-02-01T21:11:31","guid":{"rendered":"http:\/\/www.charlesescobar.com\/?p=187"},"modified":"2017-06-28T14:36:47","modified_gmt":"2017-06-28T19:36:47","slug":"script-para-escanear-la-red-desde-un-equipo-con-gnulinux","status":"publish","type":"post","link":"https:\/\/www.charlesescobar.com\/?p=187","title":{"rendered":"Script para escanear la Red desde un equipo con GNU\/Linux"},"content":{"rendered":"<p>Escanear la red desde el sistema operativo GNU\/Linux, puede ser algo tan simple como instalar el programa arp-scan<\/p>\n<p><strong>sudo apt-get install arp-scan<\/strong><\/p>\n<p>y ejecutarlo:<\/p>\n<p><strong>sudo arp-scan &#8211;interface=wlan0 &#8211;localnet<\/strong><\/p>\n<p>En el caso del ejemplo anterior escanea la red desde la interfaz wlan0, puede cambiarla a eth0 o la de su equipo.<\/p>\n<p>Pero si quiere adicionalmente escanear los puertos de los equipos que est\u00e1n activos puede hacerlo con nmap y para ello ser\u00e1 necesario un script.<\/p>\n<p>El siguiente script se puede ejecutar sin necesidad de ser root y determina primero los par\u00e1metros de red del equipo, en base a estos determina la red y n\u00famero de hosts y finalmente realiza un escaneo de la red determinando si los equipos est\u00e1n activos para\u00a0 escanear los puertos abiertos.<\/p>\n<p>Como requisito para el escaneo de puertos se requiere tener instalada la herramienta nmap<\/p>\n<p><strong>sudo apt-get install nmap<\/strong><\/p>\n<p>En caso de que nmap no est\u00e9 instalado, solo verificar\u00e1 que equipos est\u00e1n activos en la red.<\/p>\n<p>Puede descargarlo <a title=\"netyscan.sh\" href=\"http:\/\/charlesescobar.com\/info\/data\/netyscan.sh\">desde este enlace<\/a>, o copie el c\u00f3digo de abajo, p\u00e9guelo en un archivo de texto plano, cambie los permisos a ejecuci\u00f3n y ejec\u00fatelo<\/p>\n<p>==================================================================<\/p>\n<p>#!\/bin\/bash<br \/>\n# netyscan is free software; you can redistribute it and\/or modify it under the terms of the GNU General Public License<br \/>\n# as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.<br \/>\n# Charles Escobar &#8211; Enero 2015<br \/>\n# http:\/\/www.charlesescobar.com<br \/>\n# Escaneo de red clase C<br \/>\n# Determina la direcci\u00f3n del equipo, su mascara, direcci\u00f3n de red y con estos par\u00e1metros realiza el escaneo<br \/>\n# Este programa usa ping, nmap y arp<br \/>\necho \u00ab=====================================================\u00bb<br \/>\necho \u00abESCANEO DE RED CLASE C BASADA EN LA IP DE ESTE EQUIPO\u00bb<br \/>\necho \u00ab=====================================================\u00bb<br \/>\nhost=`ifconfig |grep Direc|grep inet:| awk &#8216;{ print $2 }&#8217;|sed \/127.0.0.1\/d|sed s\/inet:\/\/`<br \/>\nmascara=`ifconfig |grep Direc|grep inet:| awk &#8216;{ print $4 }&#8217;|sed \/127.0.0.1\/d|sed s\/M\u00e1sc:\/\/`<br \/>\noctmask4=`echo $mascara|awk -F \u00ab.\u00bb &#8216;{print $4}&#8217;`<br \/>\n# octmask4=248 #prueba<br \/>\nocteto1=`ifconfig |grep Direc|grep inet:| awk &#8216;{ print $2 }&#8217;|sed \/127.0.0.1\/d|sed s\/inet:\/\/| awk -F \u00ab.\u00bb &#8216;{ print $1 }&#8217;`<br \/>\nocteto2=`ifconfig |grep Direc|grep inet:| awk &#8216;{ print $2 }&#8217;|sed \/127.0.0.1\/d|sed s\/inet:\/\/| awk -F \u00ab.\u00bb &#8216;{ print $2 }&#8217;`<br \/>\nocteto3=`ifconfig |grep Direc|grep inet:| awk &#8216;{ print $2 }&#8217;|sed \/127.0.0.1\/d|sed s\/inet:\/\/| awk -F \u00ab.\u00bb &#8216;{ print $3 }&#8217;`<br \/>\nocteto4=`ifconfig |grep Direc|grep inet:| awk &#8216;{ print $2 }&#8217;|sed \/127.0.0.1\/d|sed s\/inet:\/\/| awk -F \u00ab.\u00bb &#8216;{ print $4 }&#8217;`<br \/>\n# octeto4=222 #prueba<br \/>\necho \u00abeste programa usa nmap, si no lo tiene instalado, puede hacerlo con\u00bb<br \/>\necho \u00absudo apt-get install nmap\u00bb<br \/>\nif [[ $octmask4 = 0 ]]; then<br \/>\nexpo=8<br \/>\nelse<br \/>\nexpo=`echo \u00abobase=2;$octmask4\u00bb | bc |grep -oh 0|grep -c 0`<br \/>\nfi<br \/>\nhostnum=$((2**$expo))<br \/>\noctetored=$(($octmask4 &amp; $octeto4))<br \/>\ninicio=$(($octetored + 1))<br \/>\nfin=$(($octetored + $hostnum -1))<\/p>\n<p>echo \u00abesta m\u00e1quina es:\u00bb $host \u00abM\u00e1scara:\u00bb $mascara \u00abRed:\u00bb $octeto1&#8243;.\u00bb$octeto2&#8243;.\u00bb$octeto3&#8243;.\u00bb$octetored<\/p>\n<p>echo \u00abN\u00famero de hosts: \u00bb `echo $(($hostnum-2))`<\/p>\n<p>echo \u00abEscaneo de la red: \u00bb $octeto1&#8243;.\u00bb$octeto2&#8243;.\u00bb$octeto3&#8243;.\u00bb$octetored<br \/>\necho \u00ab\u00bb<br \/>\n#exit 0<br \/>\nrango=$inicio<br \/>\nwhile [[ $rango -le $fin ]]; do<br \/>\nIP=$octeto1.$octeto2.$octeto3.$rango<br \/>\nif ping $IP -w 3 -c 1 &gt; \/dev\/null; then<br \/>\nif [[ $inactivo -eq 1 ]]; then<br \/>\necho \u00ab\u00bb<br \/>\nfi<br \/>\nmac=`arp $IP|grep ether|awk &#8216;{ print $3 }&#8217;`<br \/>\necho $IP $mac activo<br \/>\nnmap $IP|grep open<br \/>\necho \u00ab\u00bb<br \/>\ninactivo=0<br \/>\nelse<br \/>\nif [[ $inactivo -eq 1 ]] ; then<br \/>\necho -en \u00ab\\e[1A\u00bb<br \/>\necho \u00ab$IP inactivo\u00bb;<br \/>\nelse<br \/>\necho \u00ab$IP inactivo\u00bb;<br \/>\ninactivo=1<br \/>\nfi<br \/>\nfi<br \/>\nrango=$(($rango+1))<br \/>\ndone<br \/>\necho \u00abfin del escaneo\u00bb<br \/>\nexit 0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Escanear la red desde el sistema operativo GNU\/Linux, puede ser algo tan simple como instalar el programa arp-scan sudo apt-get install arp-scan y ejecutarlo: sudo arp-scan &#8211;interface=wlan0 &#8211;localnet En el caso del ejemplo anterior escanea la red desde la interfaz &#8230; <a class=\"more-link\" href=\"https:\/\/www.charlesescobar.com\/?p=187\">Leer m\u00e1s &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[2,3],"tags":[],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-articulos","category-noticias"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3vibM-31","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187"}],"version-history":[{"count":2,"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":189,"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions\/189"}],"wp:attachment":[{"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.charlesescobar.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}