Skip to main content

Check if IP is Private, Public or Invalid

Project description

##################################
Program: IPChecker
Author: Boumediene Kaddour
Country: Algeria
##################################

IPChecker is a tiny Python library that is used to check if an IP version 4 address is Private, Public or Invalid,
The library returns Booleans and contains a couple of methods summurized as follows:
isValid(): This method return True, if a valid IPv4's given, otherwise, it returns False.
isPrivate(): This little method returns True if the given IP is private, otherwise, False is returned.
isPublic(): This little method returns True if the given IP is Public, otherwise, False is returned.

Usage:
>>> from IPChecker import IPChecker
>>> obj = IPChecker("172.16.122.254")
>>> obj.isValid()
>>> True
>>> obj.isPrivate()
>>> True
>>> obj.isPublic()
>>> False

Here is an example on how you can checkout if a valid IPv4 address is given using regular expressions
in this example, i'm going to be using the built-in re module in python.

>>>def isValid(ip):
>>>_____ if findall( "(?i)^(\d|\d\d|1[0-9][0-9]|2[0-5][0-5]).(\d|\d\d|1[0-9][0-9]|2[0-5][0-5]).(\d|\d\d|1[0-9][0-9]|2[0-5][0-5]).(\d|\d\d|1[0-9][0-9]|2[0-5][0-5])$" ,ip):
>>>_________ return True
>>>_____ else:
>>>_________ return False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

IPChecker-1.1.tar.gz (1.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page