Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with ipaddress package
#1
I have some code where its reading from an input txt file... in the file are both valid IP and invalid IP, as well as valid CIDR. Im trying to do some validation before adding these IP to my firewall to make sure they are ( for the need of this case) only Public IP not private RFC1918 addresses. Here is the funciton im trying to make work:

def isPrivate_validaton():
    for newIpAddress in addressList:
        if ipaddress.ip_address(newIpAddress).is_private:
            print(newIpAddress + " this is a private address and cannot be used to access our Public SFTP service.")
            quit()
        elif ipaddress.ip_network(newIpAddress).is_private:
            print(newIpAddress) + " this is a private network CIDR and cannot be used to access our Public SFTP service"
            quit()
        else:
            continue
in my file i have the following values :
192.168.1.0/24
7.7.7.0/24

i keep getting errors stating 192.168.1.0/24 does not appear to be an IPV4 or IPV6 address and it stops.. ( as i expect it to, but the ip is a valid IP, its private but its valid). I'm sure I'm not fully understanding how the package works. But im stuck currently. Thanks in Advance for any tips.
Reply


Messages In This Thread
help with ipaddress package - by jcrubaugh45 - Jul-12-2022, 08:55 PM
RE: help with ipaddress package - by Larz60+ - Jul-12-2022, 10:08 PM
RE: help with ipaddress package - by jcrubaugh45 - Jul-12-2022, 10:26 PM
RE: help with ipaddress package - by jcrubaugh45 - Jul-12-2022, 10:27 PM
RE: help with ipaddress package - by supuflounder - Jul-13-2022, 02:01 AM
RE: help with ipaddress package - by jcrubaugh45 - Jul-13-2022, 02:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ipaddress.IPv4Network tomthirteen 11 6,831 Jan-08-2019, 10:20 PM
Last Post: tomthirteen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020