what you don't know can hurt you

pscan3.c

pscan3.c
Posted Jul 13, 2000
Authored by Ozone

Pscan3 is a simple tcp port scanner.

Changes: Compilation fixes for BSD and IRIX, better output format.
tags | tool, scanner, tcp
systems | unix
MD5 | 9404a60d4a87c432f16da00b95249705

pscan3.c

Change Mirror Download
/*              \                  /
** _________)) ((__________
** /.-------./\\ \ / //\.--------.\
** //#######//##\\ )) (( //##\\########\\
** //#######//###(( (( )) ))###\\########\\
** ((#######((#####\\ \\ // //#####))########))
** \##' `###\######\\ \)(/ //######/####' `##/
** )' ``#)' `##\`->xx<-'/##' `(#'' `(
** ( ``\`..'/'' )
** \""(
** `- )
** pscan v3.0 / / by oz0ne
** ( /\
** /\| \
** ( \
** )
** /
** (
** oz0ne7@hushmail.com
**
**
** pscan v3 is a tcp port scanner that prints the number
** of each open tcp port (within specified range) and the
** corresponding service name (if its registered) on the target host.
**
** compile: gcc pscan3.c -o pscan
** usage: ./pscan <target> <start port> <end port>
**
** Warning: scanning unauthorized hosts is illegal.
** I take no responsibility for what you choose to do with this tool.
** This code is free and without warranty
**
** 2000
*/

#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>

#define MIN_PORT 1
#define MAX_PORT 65535

void usage(char *, char *);

int main(int argc, char *argv[])
{
struct hostent *hostinfo;
struct servent *servinfo;
struct sockaddr_in address;
int port, end_port, sockfd, len, result;
char *host, **ipnum, **ipnum_buf, *service;

if (argc < 4) {
usage(argv[0], "pscan v3 by oz0ne (oz0ne7@hushmail.com)");
exit(EXIT_FAILURE);
}

host = argv[1];
hostinfo = gethostbyname(host);
if (!hostinfo) {
usage(argv[0], "pscan: unable to get info for target host");
exit(EXIT_FAILURE);
}
ipnum = hostinfo -> h_addr_list;
ipnum_buf = hostinfo -> h_addr_list;
len = sizeof(hostinfo);
port = atoi(argv[2]);
end_port = atoi(argv[3]);

printf("\npscan v3 by oz0ne (oz0ne7@hushmail.com)\n");
if (port < MIN_PORT | port > MAX_PORT) {
printf("pscan: invalid start port, using default (%d)\n", MIN_PORT);
port = MIN_PORT;
}
if (end_port < port | end_port > MAX_PORT) {
printf("pscan: invalid end port, using default (%d)\n", MAX_PORT);
end_port = MAX_PORT;
}

printf("\naddress(es): ");
while(*ipnum) {
printf("%s", inet_ntoa(*(struct in_addr *)*ipnum));
ipnum++;
}
printf("\nscanning (%s) tcp ports %d - %d\n",
inet_ntoa(*(struct in_addr*)*ipnum_buf), port, end_port);

printf("open ports:\n\n");

while ( port <= end_port ) {
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
address.sin_family = AF_INET;
address.sin_port = htons(port);
address.sin_addr = *(struct in_addr *)*hostinfo -> h_addr_list;
len = sizeof(address);
result = connect(sockfd, (struct sockaddr *)&address, len);

if (result < 0) { port++; }
else {
servinfo = getservbyport(address.sin_port, "tcp");
if (servinfo == NULL) { service = " "; }
else { service = servinfo -> s_name; }
printf("%d\t%s\n", port, service);
port++;
}
close(sockfd);
}

printf("\nDone.\n");
exit(EXIT_SUCCESS);
}


void usage(char *name, char *text) {
printf("\n%s\n\n", text);
printf("Usage: %s <target> <start port> <end port>\n", name);
printf(" target = ip address or domain name of target host\n");
printf(" start port = first port to scan\n");
printf(" end port = last port to scan\n");
}

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

June 2019

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jun 1st
    1 Files
  • 2
    Jun 2nd
    2 Files
  • 3
    Jun 3rd
    19 Files
  • 4
    Jun 4th
    21 Files
  • 5
    Jun 5th
    15 Files
  • 6
    Jun 6th
    12 Files
  • 7
    Jun 7th
    11 Files
  • 8
    Jun 8th
    1 Files
  • 9
    Jun 9th
    1 Files
  • 10
    Jun 10th
    15 Files
  • 11
    Jun 11th
    15 Files
  • 12
    Jun 12th
    15 Files
  • 13
    Jun 13th
    8 Files
  • 14
    Jun 14th
    16 Files
  • 15
    Jun 15th
    2 Files
  • 16
    Jun 16th
    1 Files
  • 17
    Jun 17th
    18 Files
  • 18
    Jun 18th
    15 Files
  • 19
    Jun 19th
    22 Files
  • 20
    Jun 20th
    15 Files
  • 21
    Jun 21st
    15 Files
  • 22
    Jun 22nd
    2 Files
  • 23
    Jun 23rd
    1 Files
  • 24
    Jun 24th
    23 Files
  • 25
    Jun 25th
    0 Files
  • 26
    Jun 26th
    0 Files
  • 27
    Jun 27th
    0 Files
  • 28
    Jun 28th
    0 Files
  • 29
    Jun 29th
    0 Files
  • 30
    Jun 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2019 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close