Category Archives: Socket Programming

Socket programming tutorials in C, Python, Perl, Php, Java and Winsock

Get ip address from hostname in C using Linux sockets

By | December 10, 2011

Socket applications often need to convert hostnames like to their corresponding ip address. This is done through dns requests. The socket api in linux provides functions like gethostbyname and getaddrinfo that can be used to perform the dns requests and get the ip address. gethostbyname The first method uses the traditional gethostbyname function to… Read More »

Code a network packet sniffer in python for Linux

By | November 29, 2011

Basic Sniffer Sniffers are programs that can capture/sniff/detect network traffic packet by packet and analyse them for various reasons. Commonly used in the field of network security. Wireshark is a very common packet sniffer/protocol analyzer. Packet sniffers can be written in python too. In this article we are going to write a few very simple… Read More »

Code a TCP Connect port scanner in PHP

By | October 24, 2011

A port scanner is a software application designed to probe a server or host for open ports. We earlier made a TCP Connect port scanner in C here – and here – Now we shall try making the same in PHP. The code is very simple : Using fsockopen Output : The above… Read More »

DNS Query Code in C with linux sockets

By | October 21, 2011

This article is an extension of the article : The Linux version has some changes. On Linux the dns server ips are stored in a file called /etc/resolv.conf. So the get_dns_servers function will open this file and pickup the dns server ip addresses. A typical /etc/resolv.conf file can look like this : # Generated… Read More »

SYN Flood DOS Attack with C Source Code (Linux)

By | May 3, 2009

TCP/IP 3-way handshake is done to establish a connection between a client and a server. The process is : 1. Client –SYN Packet–> Server 2. Server –SYN/ACK Packet –> Client 3. Client –ACK Packet –> Server The above 3 steps are followed to establish a connection between source and destination. SYN Flood DOS attacks involves… Read More »

TCP Connect Port Scanner Source Code in C with Winsock

By | April 30, 2009

Tcp connect port scanning TCP connect() scanning is the most basic form of TCP scanning. The program performs a connect() command on those ports of the target machine which are to be checked. If the port is open then the connect() command will succeed and a connection will be established. If the port is closed… Read More »