iniqua

1jul/100

Python Lib: iptools

government,politics news,politics news,politics

Esta pequeña libreria proporciona un puñado de funciones y un par de objetos que pueden utilizarse junto con Scapy para organizar y facilitar el uso de IPs.

#!/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
)

Funciones

  • 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.

Objects:

  • 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

Publicado por ffranz

Comentarios (0) Trackbacks (0)

Aún no hay comentarios.


Leave a comment

(required)

Aún no hay trackbacks.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes