Category filter

Script to find the location of a Mac using its IP address

In today’s mobile world, a huge number of employees prefer to work from the comfort of their homes or other leisure places. But keeping an eye on the type of network and the location of the device is of utmost importance to an IT admin as various security and data protocols that a company follows are at stake. Moreover, being aware of the location of an employee will also help the IT admin to apply a geofence around the device so that they can keep track of whether the device is supposed to be at the desired location to avoid any security threats. Hexnode makes it effortless for IT admins to retrieve the location, hostname, time zone, etc. of a Mac using its IP address by executing a custom script.

Scripting language – Bash

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Find the location of a Mac using its IP address

Use the following script to find the location of a Mac using its IP address.

This script fetches the IP address of the Mac along with a few parameters associated with it which are listed below:

  • IP: displays the IP address of the Mac.
  • City: displays the city where the Mac resides.
  • Region: displays the state where the Mac resides.
  • Country: displays the country where the Mac resides.
  • Loc: displays the latitude and longitude of the location where the Mac resides.
  • Org: displays the operator’s name that provides the network connection to the Mac.
  • Org: displays the operator’s name that provides the network connection to the Mac.
  • Time zone: displays the time Zone of the location where the Mac resides.
  • Readme: displays a link that takes you to the ipinfo website where everything about their plans and APIs is explained.
Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository