We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
IP Address Validation
IP Address Validation
+ 0 comments Easy Python3 solution:
# Enter your code here. Read input from STDIN. Print output to STDOUT import re ipv4 = r'^(([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.){3}([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$' ipv6 = r'^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$' for _ in range(int(input())): string = input() if re.findall(ipv4, string): print('IPv4') elif re.findall(ipv6, string): print('IPv6') else: print('Neither')
+ 0 comments for Python 3:
import re N= int(input()) for i in range(N): s = input() try: regex = re.findall(r"^([\da-f]{,4}\:){7}[\da-f]{,4}$", s) if regex: print("IPv6") else: regex = re.findall(r"^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$", s) if regex: print("IPv4") else: print("Neither") except Exception as e: pass
+ 0 comments import re r4 = re.compile(r"(([01]\d{0,2}|2[0-4]?\d?|25[0-5]|[3-9]\d{0,1})\.){3}([01]\d{0,2}|2[0-4]?\d?|25[0-5]|[3-9]\d{0,1})\s*$") r6 = re.compile(r"^([0-9a-f]{1,4}\:){7}[0-9a-f]{1,4}\s*$") lines = [input() for _ in range(int(input()))] print(*['IPv4' if r4.search(t) else 'IPv6' if r6.search(t) else 'Neither' for t in lines], sep='\n')
+ 0 comments Solution for JAVA with explanation:
Scanner scan = new Scanner(System.in); int n =scan.nextInt(); scan.nextLine();
String input = ""; Pattern ipv4 = Pattern.compile("(([0]?[0-9]?[0-9]|[1][0-9][0-9]|[2][0-5][0-5])(\\.)){3}([0]?[0-9]?[0-9]|[1][0-9][0-9]|[2][0-5][0-5])"); Pattern ipv6 = Pattern.compile("([a-f\\d]{1,4}(:){1}){7}[a-f\\d]{1,4}"); Matcher m; for(int i=0;i<n;i++){ input = scan.nextLine(); m = ipv4.matcher(input); if(m.matches()){ System.out.println("IPv4"); } else { m = ipv6.matcher(input); if(m.matches()){ System.out.println("IPv6"); } else { System.out.println("Neither"); } } input = ""; } scan.close();
+ 0 comments So, you're looking for a way to safely pay bills whether you're inside The Philippines or outside The Philippines? Then GCash is the app for you! GCash not only allows it's users to only pay bills, but also allows users to transfer and save money, plant a Tree, and allows users to even preform activities such as order food, shop and even book movie tickets! You're probably wondering how you can get involved in this useful app, right? That's why we recommend having a read of our article on how to create GCash account
Load more conversations
Sort 216 Discussions, By:
Please Login in order to post a comment