forked from bigendiansmalls/Enumeration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckp.c
96 lines (85 loc) · 2.84 KB
/
checkp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* USS Port checker for z/OS
Compile with: c89 -D _OE_SOCKETS -o checkp checkp.c
To use in TSO (after compile in Unix):
/bin/tsocmd "ALLOCATE DATASET(PDSE) NEW VOLUME(DEV) SPACE(10,10) BLOCK(200) BLKSIZE(6144) RECFM(U) LRECL(0) DSNTYPE(LIBRARY) DSORG(PO)"
cp -X ./checkp "//'<HLQ>.PDSE(CHECKP)'"
in TSO: call '<HLQ>.PDSE(CHECKP)' '<port>/-a'
License GPL
Copyright Soldier of FORTRAN
Purpose: If you don't have access to netstat
this will print a list of potential open ports
or checks on a single port.
The output is comma sperated to be copied to Nmap.
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
int checkp(int);
int checkp(int port)
{
/* Checks if a port is available for use */
struct sockaddr_in server; /* server address information */
int s; /* socket for accepting connections */
int result = 0; /* 1 open 0 closed */
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
printf("[!] ERROR Cannot open a socket! Are you sure you have permission?");
exit(2);
}
server.sin_family = AF_INET;
server.sin_port = htons(port);
server.sin_addr.s_addr = INADDR_ANY;
if (bind(s, (struct sockaddr *)&server, sizeof(server)) < 0)
{
result = 1;
}
close(s);
return result;
}
main(argc, argv)
int argc;
char **argv;
{
unsigned short port; /* port server binds to */
int results; /* We got em */
int i; /* for loop */
char* logo = "\n"
" _______ __ __ _______ \n"
"| _ | |--.-----.----| |--. | _ |\n"
"|. 1___| | -__| __| < |. 1 |\n"
"|. |___|__|__|_____|____|__|__| |. ____|\n"
"|: 1 | |: | \n"
"|::.. . | |::.| \n"
"`-------' `---' \n\n";
printf("%s", logo);
if (argc != 2)
{
fprintf(stderr, "Usage:\n Check one port: %s <port>\n Check all ports: %s -a\n\n", argv[0], argv[0]);
exit(1);
}
/* First check the arguments */
if (0 == strcmp(argv[1], "-a")) {
printf("*** You're in the butter zone now baby!\n");
printf("*** Checking ports 1 through 65535\n");
for( i = 1; i < 65535; i = i + 1 ) {
results = checkp(i);
if ( results == 1 ) {
printf(" %d,", i);
}
}
printf("\n");
} else {
port = (unsigned short) atoi(argv[1]);
printf("*** Checking if port %d is in use\n", port);
results = checkp(port);
if ( results == 1 ) {
printf("*** %d being used!\n", port);
} else {
printf("*** %d is not in use\n", port);
}
}
printf("*** Done\n\n");
exit(0);
}