简体   繁体   中英

ip address and mask in CIDR with python

I would like to convert ipaddress/mask in ipaddress/CIDR: For that two variables:

i = '192.168.0.0'
m = '255.255.255.0'

The result I'm trying to obtain is:

p to be: '192.168.0.0/24'

by using ipaddress module it would be super simple to just define like:

p = ipaddress.ip_network(i/m)

unfortunately, I get TypeError: unsupported operand type(s) for /: 'str' and 'str' which is not surprising.

How could I do that?

It works with:

p = ipaddress.ip_network(i+"/"+m)

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM