Question: 4 7 . Location Detection ALL Implement a prototype service to detect a user's location based on their IP addresses. The IP addresses belonging to

47. Location Detection
ALL
Implement a prototype service to detect a user's location based on their IP addresses.
The IP addresses belonging to the IPv4 space are conventionally represented by four octets, "a.b.c.d"
- such as 127.10.20.30. To keep it simple, these IP addresses are classified into 5 different regions indexed from 1 to 5 on the basis of the order of the bits in the first octet.
Broadly, the IP Addresses are categorized as follows:
1.0.0.0.0-127.255.255.255
2.128.0.0.0-191.255.255.255
3.192.0.0.0-223.255.255.255
4.224.0.0.0-239.255.255.255
5.240.0.0.0-255.255.255.255
Given a list of strings, ip_addresses, of size n, representing possible IPv4 addresses, for each address, determine if it is a valid IP or not, and classify it into one of the 5 classes. Return an array of n integers that represent the index of the regions for the corresponding IP addresses.
Represent an invalid IP as -1. Give me a java 8 code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!