1

I'm using ipaddress library to obtain IP address with subnet mask, but it returns wrong address after putting all data. What's the problem? When I used it earlier it was working fine.

import ipaddress
myip=ipaddress.IPv4Network('192.13.192.123/3',strict=False)

The output is 192.0.0.0/3 instead of 192.13.192.123/3

olanow20
  • 35
  • 6

1 Answers1

1

You are using IPv4Network and not ip_address.

myip = ipaddress.ip_address('192.13.192.123') will return 192.13.192.123

myip = ipaddress.IPv4Network('192.13.192.123/24', strict=False) will return 192.13.192.0/24 because the netmask is 255.255.255.0

myip = ipaddress.IPv4Network('192.13.192.123/3', strict=False) will return 192.0.0.0/24 because the netmask is 224.0.0.0

Andreas
  • 2,455
  • 10
  • 21
  • 24
Shinva
  • 1,899
  • 18
  • 25