Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the basic processing of IP address and network segment in IP address processing module IPy

Shulou Source: shulou.com Published: 2022-06-02 08:03:56 10月05日 Update

Today, I will talk to you about the basic processing of IP addresses and network segments in the IP address processing module IPy. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

First, install IPy

Wget http://www.mylinuxer.com/down/IPy-0.82a.tar.gz

[root@localhost opt] # tar-zxvf IPy-0.82a.tar.gz

[root@localhost opt] # cd python-ipy-IPy-0.82a/

[root@localhost python-ipy-IPy-0.82a] # python setup.py install

2. Basic processing of IP address and network segment

[root@localhost ~] # python

Python 2.6.6 (r266 84292, Oct 12 2012, 14:23:48)

[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

> from IPy import IP

> ip=IP ('192.168.0.0 Universe 16')

> print ip.len () # output the number of IP of this network segment

65536

> ip=IP ('192.168.1.108')

> ip.reverseNames () # reverse resolution address format

['108.1.168.192.in addr.arpa.']

> ip.iptype () # returns the network type

'PRIVATE'

> ip.int () # returns the decimal format

3232235884

> ip.strHex () # returns hexadecimal format

'0xc0a8016c'

> > ip.strDec ()

'3232235884'

Generate network segment format based on IP and mask

> ip.make_net ('255.255.0.0')

IP ('192.168.0.0amp 16')

> print ('192.168.1.108tick 255.255.255.0)

192.168.1.0/24

> print (IP ('192.168.1.108 take 255.255.0))

192.168.0.0/16

> print (IP ('192.168.1.0-192.168.1.255))

192.168.1.0/24

Specify different wantperfixlen parameter values through the strNormal method to customize network segments of different output types, which are strings.

> IP ('192.168.1.0 amp 24') .strNormal (0)

'192.168.1.0'

> IP ('192.168.1.0 amp 24') .strNormal (1)

'192.168.1.0 Compact 24'

> IP ('192.168.1.0 amp 24'). StrNormal (2)

'192.168.1.0 Compact 255.255.255.0'

> IP ('192.168.1.0 amp 24'). StrNormal (3)

'192.168.1.0-192.168.1.255'

After reading the above, do you have any further understanding of the basic processing of IP address and network segment in IP address processing module IPy? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Address network segment processing format content type output module different number hexadecimal decimal parameter character string method more knowledge article network Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Huawei Redmi MySQL