Answers for "Validate IP Address"

2

Validate IP Address

try:
            if len(IP.split('.')) == 4:
                print(IP)
                if all([bool(1) if(str(int(s)) == s and 0 <= int(s) <= 255) else bool(0) for s in IP.split('.')]):
                    return "IPv4"
            if len(IP.split(':')) == 8:
                if all([bool(1) if(len(s) <= 4 and int(s, 16) >= 0) else bool(0) for s in IP.split(':')]):
                    return "IPv6"
        except:
            return "Neither"
        return "Neither"
Posted by: Guest on August-03-2020

Python Answers by Framework

Browse Popular Code Answers by Language