Penetration testing
Netcat Command for Beginners: Connect, Listen, Transfer
Netcat, usually typed as nc, reads and writes data across network connections. It is tiny, it is on most systems, and it teaches how TCP connections work better than most tools. Use it only on your own lab or systems you have written permission to test.
A Chat Between Two Lab Machines
- On machine A, listen:
nc -lvnp 4444 - On machine B, connect:
nc 192.168.56.20 4444(use A's address) - Type on either side; the text appears on the other.
-l listens, -v is verbose, -n skips DNS and -p sets the port. Variants of netcat differ slightly, so check man nc on your system.
Check Ports and Grab Banners
nc -zv 192.168.56.20 20-100checks a range of ports without sending data.nc -v 192.168.56.20 80, then typeHEAD / HTTP/1.0and press Enter twice, shows the web server's response headers.
For serious scanning use Nmap; see Nmap for beginners.
Move a File
- Receiver:
nc -lvnp 4444 > received.txt - Sender:
nc 192.168.56.20 4444 < file.txt
There is no encryption or authentication here, which is exactly why real work uses SSH or HTTPS.
Command Cheat Sheet
nc -lvnp 4444listens on a port.nc HOST 4444connects to it.nc -zv HOST 20-100checks a port range.nc -u -lvnp 5353listens for UDP.nc HOST 4444 < file.txtsends a file.nc -lvnp 4444 > received.txtreceives one.
We ran the listen, connect, port-check and file-transfer commands between two local processes before publishing. This was the OpenBSD variant of netcat; others differ slightly.
Why Testers and Defenders Both Care
Attackers use the same idea to open a shell: a listener on one side and a connection from the compromised machine. Defenders see it as an unexpected outbound connection or listening port. Watch it in a capture with tcpdump or Wireshark, and see what blocks it in firewalls, IDS and IPS explained.
Sources and Further Reading
Want to see attack and detection side by side in a lab? Book free trial classes. Contact us or call +91 86868 92922.
Courses Mentioned in This Guide
More Guides
CEH Practical Exam and CEH Master Explained
How the CEH Practical works: 6 hours, 20 challenges in a cyber range, how it differs from the knowledge exam, what CEH Master means and how to prepare.
Read the guide →How to Prepare for CEH v13: An 8-Week Study Plan
An 8-week CEH v13 study plan: week-by-week topics, lab practice, timed question drills, exam-day pacing, and what freshers should know about eligibility.
Read the guide →EC-Council Certification Cost in India: CEH, CPENT, CND, CSA and More
What EC-Council certifications cost with us in India: CEH, CPENT AI, CND, CSA, ECIH, CTIA, CHFI, CCSE, COASP and WAHS fees, GST and what to ask.
Read the guide →Ethical Hacking Interview Questions for Freshers, with Answers
Fifteen ethical hacking and penetration testing interview questions for freshers with short model answers: phases, OWASP, injection, scanning, scope and reporting.
Read the guide →Start Your Cyber Security Career
Talk to a counselor, choose the right course for your goals, and get the fee, syllabus and next batch dates in writing.
- Call+91 86868 92922
Open 7 days: Mon to Fri 8:30 AM to 8:30 PM IST
Sat and Sun 10 AM to 6 PM IST - Emailinfo@hackingtrainer.com
- VisitGround Floor, G-3, Sri Venkatasai Nest, Kallu Compound Road, Nagarjuna Nagar Colony, Yella Reddy Guda, Ameerpet, Hyderabad – 500073
Open in Google Maps