validate ip address

Solutions on MaxInterview for validate ip address by the best coders in the world

showing results for - "validate ip address"
Leora
24 May 2019
1try:
2            if len(IP.split('.')) == 4:
3                print(IP)
4                if all([bool(1) if(str(int(s)) == s and 0 <= int(s) <= 255) else bool(0) for s in IP.split('.')]):
5                    return "IPv4"
6            if len(IP.split(':')) == 8:
7                if all([bool(1) if(len(s) <= 4 and int(s, 16) >= 0) else bool(0) for s in IP.split(':')]):
8                    return "IPv6"
9        except:
10            return "Neither"
11        return "Neither"