pscan2.c is a simple tcp port scanner.
b0d7e7fb643bea96a8889be0860892cb5a5daa4d44c3329f0e9a5920ab3a4566
/* \ /
* _________)) ((__________
* /.-------./\\ \ / //\.--------.\
* //#######//##\\ )) (( //##\\########\\
* //#######//###(( (( )) ))###\\########\\
* ((#######((#####\\ \\ // //#####))########))
* \##' `###\######\\ \)(/ //######/####' `##/
* )' ``#)' `##\`->xx<-'/##' `(#'' `(
* ( ``\`..'/'' )
* \""(
* `- )
* pscan v2.0 / / by oz0ne
* ( /\
* /\| \
* ( \
* )
* /
* (
* oz0ne7@hushmail.com
*
*
* pscan is a basic port scanner that prints the number
* of each open port (within specified range) on the target host.
* It can take an ip address or a domain name as its argument.
*
* compile: gcc pscan2.c -o pscan
* usage: ./pscan <ipnumber> | <domainname>
*
* 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
*
*/
#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>
#include <signal.h>
#define START_PORT 1
#define END_PORT 1024
void quit(int);
int usage(char *);
int main(int argc, char *argv[])
{
char *host, **names, **addrs;
struct hostent *hostinfo;
struct sockaddr_in address;
int port, sockfd, len, result;
struct sigaction act;
act.sa_handler = quit;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGINT, &act, 0);
if (argc == 1) {
usage(argv[0]);
exit(EXIT_FAILURE);
}
else { host = argv[1]; }
hostinfo = gethostbyname(host);
if (!hostinfo) {
fprintf(stderr, "Error: cannot get info for host: %s:\n", host);
exit(EXIT_FAILURE);
}
printf("Results for %s\n", host);
printf("Name: %s\n", hostinfo -> h_name);
printf("Aliases:");
while(*names) {
printf("%s ", **names);
names++;
}
printf("\n");
if(hostinfo -> h_addrtype != AF_INET) {
fprintf(stderr, "Error: Not an IP host!\n");
exit(EXIT_FAILURE);
}
addrs = hostinfo -> h_addr_list;
while (*addrs) {
printf(" %s", inet_ntoa(*(struct in_addr *)*addrs));
addrs++;
}
printf("\n");
printf("Scanning ports %d - %d\n", START_PORT, END_PORT);
printf("Open ports:\n");
port = START_PORT;
while ( port <= END_PORT ) {
sockfd = socket(AF_INET, SOCK_STREAM, 0);
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 == -1) { port++; }
else {
printf("%d\n", port);
port++;
}
close(sockfd);
}
printf("Done.\n");
exit(EXIT_SUCCESS);
}
void quit(int sig) {
printf("Process Interupted!!\n");
printf("Done.\n");
exit(EXIT_FAILURE);
}
int usage(char *name) {
printf("pscan v2.0 by oz0ne (oz0ne7@hushmail.com)\n");
printf("Usage: %s <ipaddress> | <domainname>\n", name);
return(1);
}