1jul/100
Python Lib: iptools
#!/usr/bin/env python
import iptools
INTERNAL_IPS = iptools.IpRangeList(
'127.0.0.1', # single ip
'192.168/16', # CIDR network block
('10.0.0.1', '10.0.0.19'), # inclusive range
)
- validate_ip: Validar una dirección IP.
- validate_cidr: Valida el CIDR de una dirección IP.
- cidr2block: Convierte la notación CIDR en una tupla donde se muestra la IP de inicio y la IP final.
- IpRange: Rango de IPs 'iterable'.
- IpRangeList: Listado de rangos de IPs 'iterables'.
+info: http://code.google.com/p/python-iptools/
Con esta pequeña libreria podemos implementar, por ejemplo, pruebas con 'Martian IPs'.
Sirva como ejemplo el siguiente script:
#!/usr/bin/env python
from commands import *
import iptools
#Get broadcast IP (must choose the correct interface)
com="ifconfig eth0 | grep 'inet '| grep -v '127.0.0.1' | cut -d: -f3 | awk '{ print $1}'"
Bcast = getoutput(com)
#Declare IPTools objects
SRC_MARTIAN_IPS = iptools.IpRangeList(
'127.0.0.0/8',
'0.0.0.0',
'255.255.255.255',
('224.0.0.0','239.255.255.255'),
Bcast,
)
DST_MARTIAN_IPS = iptools.IpRangeList(
'127.0.0.0/8',
'0.0.0.0',
('224.0.0.0','239.255.255.255'),
)
for ip in SRC_MARTIAN_IPS: # Use each IP in scapy functions
print ip
for ip in DST_MARTIAN_IPS: # Use each IP in scapy functions
print ip
Download & install
- Python package index: wget pypi.python.org/pypi/iptools/
- Version estable:
easy_install iptools
pip install iptools
- Version Development:
svn checkout http://python-iptools.googlecode.com/svn/trunk/ python-iptools cd python-iptools python setup.py install
Comentarios (0)
Trackbacks (0)
( suscribirse a los comentarios de esta entrada )
Aún no hay trackbacks.