Getting GPS location via network is VERY easy on Linux. All you need to do is to communicate with communicate with external services like ipvigilante.com
or freegeoip.com
and you'll get all the geo-location information based on the connected network (whether it is via LAN or wifi).
Keep in mind that the location sourced from this location will not be accurate since it relies heavily on the network nodes and server itself. You will need to cope with other information, such as scraping the router nodes and gateway to provide some clues. Also, this is definitely would not work if the machine is connected via VPN, especially high-level anonymity like Tor network.
Once you obtain the JSON replies, you can either:
Always keep in mind that unauthorized geo-locating a machine/person is an intrusion to an individual privacy. Hence, please practice with ethics.
Since this is using network communications, you need at minimum, to install cURL package. Here is an example from Debian:
$ sudo apt install curl -y
The command:
$ curl --fail --silent --request GET \
--url https://ipvigilante.com/8.8.8.8
# with specific IP
$ curl --fail --silent --request GET \
--url https://ipvigilante.com/8.8.8.8
You will get a JSON reply from the server with:
A far and more accurate geo-location identifier.
curl --fail --silent --request GET \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--url https://freegeoip.app/json/
# with specific IP
curl --fail --silent --request GET \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--url https://freegeoip.app/json/8.8.8.8
This provides:
The command:
$ curl --fail --silent --request GET \
--url https://ipapi.co/json/
# With specific IP
$ curl --fail --silent --request GET \
--url https://ipapi.co/8.8.8.8/json/
This provides:
The command:
$ curl --fail --silent --request GET \
--url extreme-ip-lookup.com/json/
# with specific IP
$ curl --fail --silent --request GET \
--url extreme-ip-lookup.com/json/8.8.8.8
That's all about finding Linux machine geo-location via network connection.