Table of Contents

Nmap

Nmap - A versatile network security scanning tool used for threat detection and anomaly detection in infrastructure environments. https://github.com/nmap/nmap

nmap is a network scanning tool used to discover hosts and services on a computer network. Nmap is widely used by system administrators and security professionals to map out network topologies, find open ports, and detect vulnerabilities.

https://formulae.brew.sh/formula/nmap

Examples

 def scan_network(target):
     nm = nmap.PortScanner()
     nm.scan(target, '1-1024')
     for host in nm.all_hosts():
         print(f'Host : {host} ({nm[host].hostname()})')
         print(f'State : {nm[host].state()}')
         for proto in nm[host].all_protocols():
             print('----------')
             print(f'Protocol : {proto}')
             lport = nm[host][proto].keys()
             for port in lport:
                 print(f'port : {port}\tstate : {nm[host][proto][port]["state"]}')
 # Scan the local network
 scan_network('192.168.1.0/24')
 ```

 public class NmapExample {
     public static void runNmapScan(String target) {
         try {
             Process process = new ProcessBuilder("nmap", "-sP", target).start();
             BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
             String line;
             while ((line = reader.readLine()) != null) {
                 System.out.println(line);
             }
             reader.close();
             int exitCode = process.waitFor();
             if (exitCode != 0) {
                 BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                 while ((line = errorReader.readLine()) != null) {
                     System.err.println("Error: " + line);
                 }
                 errorReader.close();
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
     public static void main(String[] args) {
         // Run nmap scan on the local network
         runNmapScan("192.168.1.0/24");
     }
 }
 ```

Summary