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