How to scan local area network with Terminal on macOS

Terminal on macOS is a handy tool but few people use it. This article will guide you to use Terminal in macOS to scan local area network for troubleshooting and maintenance.

Terminal on macOS is a handy tool but few people use it. This article will guide you to use Terminal in macOS to scan local area network for troubleshooting and maintenance. The macOS terminal works a bit differently than the Linux utility with some other flags. So don't assume all Linux Terminal skills will work correctly on macOS.

  1. How to determine the device IP address on the local network
  2. Instructions for installing LAN with systems using multiple operating systems
  3. Share a folder on local network for new users

Scan the open ports of local area network with nmap

Nmap is a command line port scanner on macOS but you need to install it first to use it.

Install nmap with Homebrew

If Homebrew is already installed, run the following command to download and install nmap and the required dependencies.

  1. Instructions for installing the software using Homebrew on macOS X
 brew install nmap 

Scanning with nmap

The nmap is built to scan the hostname or network address provided and return a list of open ports. nmap stands for network mapper but performs a role as a port mapper (port mapper).

The simplest way to run nmap is with the IP address or the specified IP address range as the target. Run the following command with the appropriate IP address to scan your local network. Here the command scans nmap's test server at scanme.org.

 nmap 74.207.244.221 nmap scanme.org 

How to scan local area network with Terminal on macOS Picture 1How to scan local area network with Terminal on macOS Picture 1

To scan open ports on a range of IP addresses, use a forward slash.

 nmap 192.181.0.0/24 

To find the IP address for routers and other devices on the network, run arp or ipconfig .

 sudo nmap -A scanme.org 

How to scan local area network with Terminal on macOS Picture 2How to scan local area network with Terminal on macOS Picture 2

Use -A flag to force nmap to scan faster and stronger, return more information and clearly reveal your presence in server logs. -A flag needs to run with sudo.

 sudo nmap -O scanme.org 

How to scan local area network with Terminal on macOS Picture 3How to scan local area network with Terminal on macOS Picture 3

The above command scans the specified IP address for the operating system ( -O ).

If you want to run nmap 'stealth' a bit, use the -sS flag:

 sudo nmap -sS scanme.org 

The above command scans the first half, sends a TCP SYN packet to check for an open port but does not respond to an ACK packet when it receives a confirmation response. Therefore, the remote server may not log scans.

The -sS flag and other scan mode switches must run with sudo. For example, the -sP mode switch will scan the IP address but not the port, acting like the arp below. You can visit the main page of nmap for more scanning modes.

To get longer results, add -vv or -v3 tags to enable longer logging, create a longer, more readable standard output, depending on the search content, these flags will help you find it. .

Of course, you can use grep to search for specific results. If you only want to search for port 22, you can run the following command:

 nmap scanme.org | grep "22/tcp" 

The above command will return status if there is a port and nothing if there is no port.

How to scan local area network with Terminal on macOS Picture 4How to scan local area network with Terminal on macOS Picture 4

Scan the active IP address of the local network with arp

arp scans the local area network for connected devices. Because arp is designed to create and edit address resolution protocols, few network scanning tools are available. But it is available on every Mac and is a quick way to get specific information.

To see a list of all devices currently connected to the network, open Terminal and run:

 arp -a 

How to scan local area network with Terminal on macOS Picture 5How to scan local area network with Terminal on macOS Picture 5

The above command returns a list of all devices connected to your network, reporting by IP and MAC address.

How to scan local area network with Terminal on macOS Picture 6How to scan local area network with Terminal on macOS Picture 6

You can run arp -a -i en0 to receive only reports from the en0 network interface.

The most powerful tool for scanning local area networks on macOS is nmap. arp is also useful for running pings on the network. Ipconfig can report results for specific interfaces but is more useful when reporting interface information than scanning the network.

I wish you successful implementation!

4.2 ★ | 13 Vote

Maybe you are interested