Java Socket Programming and Nmap Network Scanning

Classified in Computers

Written on in English with a size of 3.5 KB

Java Socket Programming Implementation

Code: Server-Side

import java.io.*;
import java.net.*;

public class MyServer {
    public static void main(String[] args) {
        try {
            ServerSocket ss = new ServerSocket(6666);
            Socket s = ss.accept();
            DataInputStream dis = new DataInputStream(s.getInputStream());
            String str = (String) dis.readUTF();
            System.out.println("Message: " + str);
            ss.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

Client-Side Code:

import java.io.*;
import java.net.*;

public class MyClient {
    public static void main(String[] args) {
        try {
            Socket s = new Socket("localhost", 6666);
            DataOutputStream dout = new DataOutputStream(s.getOutputStream());
            dout.writeUTF("Hello Server");
            dout.flush();
            dout.close();
            s.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

Essential Nmap Commands for Network Scanning

  1. Nmap -sn <ip_address>: This command scans a single IP address for open ports.
  2. Nmap -sP <network range>: This command scans a range of IP addresses for active hosts.
  3. Nmap -sV <ip_address>: This command scans a single IP address for open ports and their associated services.
  4. Nmap -sT <ip_address>: This command scans a single IP address for open ports using TCP SYN packets.
  5. Nmap -sU <ip_address>: This command scans a single IP address for open ports using UDP packets.
  6. Nmap -O <ip_address>: This command scans a single IP address for its operating system and other identifying information.
  7. Nmap -A <ip_address>: This command scans a single IP address for open ports, operating system, and other identifying information.
  8. Nmap -p <port> <ip_address>: This command scans a single IP address for a specific port.
  9. Nmap -p 1-1024 <ip_address>: This command scans a single IP address for all ports from 1 to 1024.
  10. Nmap -p 80,443 <ip_address>: This command scans a single IP address for the HTTP (port 80) and HTTPS (port 443) ports.
  11. Nmap -iL <file_name>: This command scans a list of IP addresses from a file.
  12. Nmap -iR <number>: This command scans a random range of IP addresses for active hosts.
  13. Nmap -v <ip_address>: This command prints out verbose output for a single IP address scan.
  14. Nmap -oN <file_name> <ip_address>: This command saves the output of a scan to a file.
  15. Nmap -oX <file_name> <ip_address>: This command saves the output of a scan to an XML file.
  16. Nmap -oG <filename> <ip_address>: This command saves the output of a scan to a Greppable format file.
  17. Nmap --script <script name> <ip_address>: This command runs a specific Nmap script against a single IP address.

Related entries: