Pscan v1.0 is a small Unix TCP port scanner that uses connect().
083849c2a726c95512fd1ffc2651fa15ab2444c2dd87892be6d50c0f332c2395
/*
Pscan v1.0 - Simple UNIX based TCP port scanner
Tested on Redhat Linux 7.2
++ Scans all 65535 TCP ports on a 100 Mbps Ethernet LAN in just 15 seconds !!
Compile: gcc -o Pscan Pscan.c
(c) 2002 by Benny T. <allegro16@hotmail.com>
*/
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
void Usage();
void main(int argc,char *argv[])
{
int i,dots=0;
int sock,portcount;
struct sockaddr_in sain;
if(argc!=4) {
Usage();
exit(0);
}
for(i=0;i<strlen(argv[1]);i++) {
if(argv[1][i]=='.') {
dots++;
}
}
if(dots!=3) {
printf("Invalid IP address\n");
Usage();
exit(0);
}
if(atoi(argv[2]) > 65535 || atoi(argv[3]) > 65535) {
printf("Invalid port number\n");
Usage();
exit(0);
}
sock = socket(AF_INET,SOCK_STREAM,0);
if(sock<0) {
printf("Error creating socket\n");
exit(0);
}
portcount = 0;
printf("Scanning host ");
printf(argv[1]);
printf(".....\n\n");
sain.sin_family=AF_INET;
sain.sin_addr.s_addr=inet_addr((char *)argv[1]);
for(i=atoi(argv[2]);i<=atoi(argv[3]);i++) {
sain.sin_port=htons(i);
if(connect(sock,(struct sockaddr *)&sain,sizeof(sain))==0) {
portcount++;
printf("Port ");
printf("%d",i);
printf(" open\n");
close(sock);
sock = socket(AF_INET,SOCK_STREAM,0);
if(sock<0) {
printf("Error creating socket\n");
exit(0);
}
}
}
printf("\n");
printf("%d%s",portcount, " TCP port(s) open\n");
close(sock);
}
void Usage()
{
printf("\nPscan v1.0 - Simple UNIX based TCP port scanner\n");
printf("(c) 2002 by Benny T. <mailto:allegro16@hotmail.com>\n");
printf("Usage: Pscan <IP address> <From port> <To port>\n\n");
}