Ir para o conteúdo
ou

Software livre Brasil

 Voltar a Projeto Soft...
Tela cheia Sugerir um artigo

Marvin Lemos: IPy – A Python module for handling IPv4 and IPv6 Addresses and Networks

2 de Dezembro de 2011, 0:00 , por Software Livre Brasil - 0sem comentários ainda | Ninguém está seguindo este artigo ainda.
Visualizado 51 vezes

IPy is a Python module for handling IPv4 and IPv6 Addresses and Networks in a fashion similar to perl’s Net::IP and friends. The IP class allows a comfortable parsing and handling for most notations in use for IPv4 and IPv6 Addresses and Networks.
It enables code like this:

      >>> ip = IP('127.0.0.0/30')
      >>> for x in ip:
      ...  print x
      ...
      127.0.0.0
      127.0.0.1
      127.0.0.2
      127.0.0.3
      >>> ip2 = IP('0x7f000000/30')
      >>> ip == ip2
      1
      >>> ip.reverseNames()
      ['0.0.0.127.in-addr.arpa.', '1.0.0.127.in-addr.arpa.',
      '2.0.0.127.in-addr.arpa.', '3.0.0.127.in-addr.arpa.']
      >>> ip.reverseName()
      '0-3.0.0.127.in-addr.arpa.'
      >>> ip.iptype()
      'RESERVED'

It can detect about a dozen different ways of expressing IP addresses and networks, parse them and distinguish between IPv4 and IPv6 addresses.

      >>> IP('10.0.0.0/8').version()
      4
      >>> IP('::1').version()
      6
      >>> print IP(0x7f000001)
      127.0.0.1
      >>> print IP('0x7f000001')
      127.0.0.1
      >>> print IP('127.0.0.1')
      127.0.0.1
      >>> print IP('10')
      10.0.0.0
      >>> print IP('1080:0:0:0:8:800:200C:417A')
      1080:0000:0000:0000:0008:0800:200c:417a
      >>> print IP('1080::8:800:200C:417A')
      1080:0000:0000:0000:0008:0800:200c:417a
      >>> print IP('::1')
      0000:0000:0000:0000:0000:0000:0000:0001
      >>> print IP('::13.1.68.3')
      0000:0000:0000:0000:0000:0000:0d01:4403
      >>> print IP('127.0.0.0/8')
      127.0.0.0/8
      >>> print IP('127.0.0.0/255.0.0.0')
      127.0.0.0/8
      >>> print IP('127.0.0.0-127.255.255.255')
      127.0.0.0/8

      >>> IP('10.0.0.0/24').strNormal(q)
      '10.0.0.0/24'
      >>> IP('10.0.0.0/24').strNormal(2)
      '10.0.0.0/255.255.255.0'
      >>> IP('10.0.0.0/24').strNormal(3)
      '10.0.0.0-10.0.0.255'

Read the full article HERE.


Fonte: http://www.marvinlemos.net/?p=346

0sem comentários ainda

Enviar um comentário

Os campos são obrigatórios.

Se você é um usuário registrado, pode se identificar e ser reconhecido automaticamente.