Mostrando entradas con la etiqueta Networking. Mostrar todas las entradas
Mostrando entradas con la etiqueta Networking. Mostrar todas las entradas

CheckHostAlive.bash

d
Nombre: CheckHostAlive.bash
Autor: @Tonejito
Descripción: Script que permite verificar si un host se encuentra arriba en la red,muestra un "0" si está arriba y un "1" si está abajo
Visto en: Tonejito
#!/bin/sh


# Check all hosts within the network
# BSD license


PING=/sbin/ping
SEQ=gseq


NET=192.168.2
ME=192.168.0.2


i=1;
while [ $i -le 254 ] ;
do
  $PING -v -D -s 8 -t 1 -w 1 -c 1 -I $ME $NET.$i 1>/dev/null
  printf "$?"
  i=`expr $i + 1` ;
done


printf "\n"
Permisos: chmod 700 CheckHostAlive.bash 
Ejecución: ./CheckHostAlive.bash.
Nota: El script mandará el ping del primer nódo al último [ 0-254 ]
Leer más...

Show2.bash

d
Nombre: Show2.bash
Autor: @_tty0
Descripción: Script que te muestra la IP pública.
Visto en tty0
#!/bin/bash
# Print the current Internet IP address

#--- CONFIG HERE ---
CURL='/usr/bin/curl'
NC='/usr/bin/netcat'
SERVER='http://checkip.dyndns.org/'
PORT=80
#--------------------

[ -e ${CURL} ] && ( ${CURL} -s ${SERVER} | tr '>' '\n' | tr '<' '\n' | grep 'Current IP Address:' ; exit $? )

[ -e ${NC}   ] && ( echo -ne "GET /index.html HTTP/1.0\n\n" | \
                  ${NC} ${SERVER} ${PORT} | tr '>' '\n' | tr '<' '\n' | \
                  grep 'Current IP Address:' | sed 's|Current IP Address:|inet ip:|g'; exit $? ) 
Permisos: chmod 700 show2.bash 
Ejecución: ./show2.bash
Leer más...

Show.bash

d
Nombre: Show.bash
Autor: @Tonejito
Descripción: Script que te muestra la IP privada
Visto en Tonejito
#!/bin/sh

IP=/bin/ip
SED=/bin/sed
CUT=/usr/bin/cut

IF=en0

if [ ! -z ${1} ]
then
  IF=${1}
fi

$IP addr show dev $IF | $SED -n 3p | $SED -e 's/\ \+/\ /g' -e 's/\/.*$//g' | $CUT -d ' ' -f 3
Permisos: chmod 700 show.bash 
Ejecución: ./show.bash
Leer más...

revoke-ssh.bash

d
Nombre: revoke-ssh
Autor: nixCraft.
Descripción: Script que permite remover una entrada del archivo ~/.known_hosts, muy útil cuando se ha reinstalado o cuando las llaves ssh han cambiado.
Visto en tty0
#!/bin/bash
# A simple shell script to clean (delete)  ~/.known_hosts file hostname entry.
# This is useful when remote server reinstalled or ssh keys are changed!
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project [http://cyberciti.biz/fb/]
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
host="$1"
 
[[ $# -eq 0 ]] && { echo "Usage: $0 host.name.com"; exit 1;}
 
ips=$(host "$host" | awk -F'address' '{ print $2}' | sed -e 's/^ //g')
ssh-keygen -R "$host"

for i in $ips
do
  ssh-keygen -R "$i"
done

exit $?
Permisos de ejecución: chmod 700 revoke-ssh.bash 
Ejecución del script: ./revoke-ssh.bash nombre.dominio o ./revoke-ssh.bash IP.
Leer más...

Verificar conexión a la red

d
Autor: @WizardIP
Descripción: Script que mediante wget verifica si hay conexión a la red.
#!/bin/bash

WGET="/usr/bin/wget"
$WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];
then echo "No"
else echo "Si"
fi
exit 0
Leer más...

Netstat Conexiones Activas

d
Autor: Desconocido
Descripción: Script que muestra las conexiones activas del host.


sudo ls &>/dev/null
if [ $? -ne 0 ]; then
echo "El usuario no tiene permisos de administrador"
exit 1
fi

parse_num()
{
x=$(echo $1 | sed -n 's/0*//p')
if [ $(echo $x | wc -c) -eq 1 ]
then
x=0
fi
echo $x
}


hex_to_ip()
{
index=7
output=''
while [ $index -gt 0 ]
do
end=$(expr $index + 1)
value=$(printf "%d" "0x$(parse_num $(echo $1 | cut -b $index-$end))")
output="$output.$value"
index=$(expr $index - 2)
done
echo $(echo $output | cut -b 2-)
}
printf " Src IP Src port Dst IP Dst port\n"

cat /proc/net/tcp | while read line; do
srcip=$(hex_to_ip $(echo $line | sed -n 's/^[0-9]*: //p' | sed 's/:.*//p'))
srcport=$(printf "%d" 0x$(parse_num $(echo $line | sed -n 's/^ *[0-9]*: [0-9,A-F]*://p' | cut "-d " -f 1)))
dstip=$(hex_to_ip $(echo $line | sed -n 's/^[0-9]*: [0-9,A-F]*:[0-9,A-F]* //p' | sed -n 's/:.*//p'))
dstport=$(printf "%d" 0x$(parse_num $(echo $line | sed -n 's/^ *[0-9]*: [0-9,A-F]*:[0-9,A-F]* [0-9,A-F]*://p' | cut "-d " -f1)))

printf "%15s %9s %15s %9s\n" $srcip $srcport $dstip $dstport
done

netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c

exit 0
Leer más...

Configuración de red de dos tarjetas en Ubuntu

d
Autor: @javcasta
Función: Script que configura 2 tarjetas de red.

#!/bin/bash
# Script de configuracion de red, DNSs, ruta por defecto y llamada a reglas de IpTables

# RED
# parametros de red
ipeth0=10.50.66.3;masketh0=255.255.255.0;redeth0=10.50.66.0;broadcasteth0=10.50.66.255;gweth0=10.50.66.1
ipeth1=192.168.1.1;masketh1=255.255.255.0;redeth1=192.168.1.0;broadcasteth1=192.168.1.255
echo Configurando los interfaces de red y el DNS. ...
echo "auto lo" > /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
echo "# eth0 interfaz conectado al router" >> /etc/network/interfaces
echo "auto eth0" >> /etc/network/interfaces
echo "iface eth0 inet static" >> /etc/network/interfaces
echo " address $ipeth0" >> /etc/network/interfaces
echo " netmask $masketh0" >> /etc/network/interfaces
echo " network $redeth0" >> /etc/network/interfaces
echo " broadcast $broadcasteth0" >> /etc/network/interfaces
echo " gateway $gweth0" >> /etc/network/interfaces
echo "# eth1 interfaz conectado a la LAN" >> /etc/network/interfaces
echo "auto eth1" >> /etc/network/interfaces
echo "iface eth1 inet static" >> /etc/network/interfaces
echo " address $ipeth1" >> /etc/network/interfaces
echo " netmask $masketh1" >> /etc/network/interfaces
echo " network $redeth1" >> /etc/network/interfaces
echo " broadcast $broadcasteth1" >> /etc/network/interfaces
echo "# Ruta de ultimo recurso" >> /etc/network/interfaces
echo "up route add -net 0.0.0.0/0 gw $gweth0 dev eth0" >> /etc/network/interfaces
echo "# aplicamos reglas de iptables" >> /etc/network/interfaces
echo "pre-up iptables-restore < /home/usuario/scripts/iptables.reglas.javcasta.up" >> /etc/network/interfaces
echo "# ---- by javcasta - 2.011 - http://javcasta.com ---" >> /etc/network/interfaces
# DNSs
dns1=208.67.222.222
dns2=208.67.220.220
nombreservidor=$(hostname -s)
dominio=$(hostname -d)
echo "# by script - 2.011" > /etc/resolv.conf
echo "search $dominio" >> /etc/resolv.conf
echo "domain $dominio" >> /etc/resolv.conf
echo "nameserver $dns1" >> /etc/resolv.conf
echo "nameserver $dns2" >> /etc/resolv.conf
# habilitar enrutamiento
echo "1" > /proc/sys/net/ipv4/ip_forward
# reiniciamos servicio de red
#service networking restart
/etc/init.d/networking restart
Configura lo siguiente:

  • Los parámetros tcp/ip de las dos tarjetas (NICs)
  • Los DNs
  • La ruta por defecto o de último recurso
  • La llamada a un script de ipTables
  • Habilitar el enrutamiento
  • Leer más...