Category : "Coding"

All kinds of Programming.

Perl port scanner code

Tcp connect port scanner in perl A tcp connect port scanner works on the principle of establishing a full tcp connection on a port it wants to check. Therefore a port scanner is quite easy to code, as it just connects to all required ports one by one and whenever a connection is established, reports that port as open. To code such ...

Close open ports manually in ubuntu

Open ports When doing a lot of socket programming, it often happens that a server program when recompiled/rerun fails to bind to a particular port number because that port number is already in use. To close the port number manually first the process name/id has to be found out that is holding the port open and then use the kill command on ...

Udp socket programming in Java

Datagram sockets UDP sockets can be used in java with the DatagramSocket class. Server Let code a simple udp server that listens on a certain port number. /** Java ECHO server with UDP sockets example */ import java.io.*; import java.net.*; public class udp_server { public static void main(String args) { DatagramSocket sock = null; try { //1. creating a server socket, parameter is local port number sock = new DatagramSocket(7777); //buffer to receive incoming data byte buffer = new ...

Code a packet sniffer in python with pcapy extension

Pcapy In the previous articles we coded packet sniffers in python using raw sockets. Now lets use the libpcap library for the same. Libpcap is the packet capture library for linux and has wrappers for most languages. In python there are multiple libpcap wrappers like pcapy, pypcap etc. In this article we shall use the pcapy python module. Pcapy is a Python ...

Code a simple socket client class in c++

Wrapper class for socket functions The standard socket library in C comes with a lot of functions for every task like connecting, sending data and receiving data etc. However knowing the syntax of all the functions and calling them again and again and in the right sequence could be a bit intimidating. Using a class can help in such a situation. ...

Receive full data with recv socket function in C

recv The recv function is used to receive data on a socket. For example here is the code to fetch the home page of www.msn.com /** Simple TCP client to fetch a web page */ #include<stdio.h> #include<string.h> //strlen #include<sys/socket.h> #include<arpa/inet.h> //inet_addr int main(int argc , char *argv) { int socket_desc; struct sockaddr_in server; char *message , server_reply; //Create socket socket_desc = socket(AF_INET , SOCK_STREAM , 0); if (socket_desc == -1) { printf("Could not create socket"); } //ip address of www.msn.com (get by ...

UDP socket programming in php

In a previous article we learnt about writing simple server and clients using TCP sockets in php. In this article we are going to use udp sockets for the same. UDP sockets are much simpler to work with since they are connection-less. A udp server just has an socket that waits to receive some data and a socket client can send ...

UDP socket programming in winsock

UDP sockets UDP stands for User Datagram Protocol and is an alternative protocol to TCP the most common protocol used for data transfer over the internet. UDP is different from TCP in a number of ways. Most importantly UDP is a connectionless protocol. In the TCP protocol first a connection is established by performing the 3 step handshake. This is done by ...

Programming udp sockets in C on Linux

UDP sockets This article describes how to write a simple echo server and client using udp sockets in C on Linux/Unix platform. UDP sockets or Datagram sockets are different from the TCP sockets in a number of ways. The most important difference is that UDP sockets are not connection oriented. More technically speaking, a UDP server does not accept connections and ...

Receive full data with the recv socket function in python

In an earlier article we saw how to send and receive data in python using sockets. Lets take a quick example : #Socket client example in python import socket #for sockets import sys #for exit #create an INET, STREAMing socket try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) except socket.error: print 'Failed to create socket' sys.exit() print 'Socket Created' host = 'www.google.com'; port = 80; try: remote_ip = socket.gethostbyname( host ) except socket.gaierror: #could not resolve print 'Hostname could not be resolved. ...



Connect with us