forked from OpenFireTechnologies/PortScanner
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPort_Scanner.java
More file actions
134 lines (124 loc) · 5.17 KB
/
Port_Scanner.java
File metadata and controls
134 lines (124 loc) · 5.17 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import java.io.*;
import java.util.*;
import java.net.*;
class Port_Scanner
{
static long start=0;
static long stop=0;
static float timetaken=0;
static int port=0;
static int limit=0;
static ArrayList <Integer>open_ports;
//FUNCTION TO DISPLAY BANNER-----------------------
public static void BANNER()
{
System.out.print( " >===> >=======> \n"+
" >=> >=> >=> >> \n"+
">=> >=> >=> >=> >==> >==>> ==> >=> >> >==> >==> \n"+
">=> >=> >> >=> >> >=> >=> >=> >=====> >=> >=> >> >=> \n"+
">=> >=> >> >=> >>===>>=> >=> >=> >=> >=> >=> >>===>>=> \n"+
" >=> >=> >=> >=> >> >=> >=> >=> >=> >=> >> \n"+
" >===> >=> >====> >==> >=> >=> >=> >==> >====> \n"+
" >=> \n");
System.out.print( " ::::::'##:::'###:::'##::::'##:::'###:::: \n"+
" :::::: ##::'## ##:::##:::: ##::'## ##::: \n"+
" :::::: ##:'##:. ##::##:::: ##:'##:. ##:: \n"+
" :::::: ##'##:::. ##:##:::: ##'##:::. ##: \n"+
" :##::: ##:#########. ##:: ##::#########: \n"+
" :##::: ##:##.... ##:. ## ##:::##.... ##: \n"+
" . ######::##:::: ##::. ###::::##:::: ##: \n"+
" :......::..:::::..::::...::::..:::::..:: \n");
System.out.print( "###### ##### \n"+
"# # #### ##### ##### # # #### ## # # # # ###### ##### \n"+
"# # # # # # # # # # # # ## # ## # # # # \n"+
"###### # # # # # ##### # # # # # # # # # ##### # # \n"+
"# # # ##### # # # ###### # # # # # # # ##### \n"+
"# # # # # # # # # # # # # ## # ## # # # \n"+
"# #### # # # ##### #### # # # # # # ###### # # \n\n");
System.out.println(" {*} OpenFire Java Port Scanner {*} \n"+
" {*} Developed by:- Supratik Banerjee (drakula941) {*} \n"+
" {*} Homepage:- http://www.openfire-security.net/ {*} \n"+
" {*} Version:- 1.1 {*} \n\n");
}
//MAIN FUNCTION-----------------------
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
InetAddress rslt=null;
String IP="";
String opt="";
do
{
BANNER();
open_ports=new <Integer>ArrayList();
try
{
//IP input is taken from the user
System.out.println("Enter the IP address");
IP=br.readLine();
if(IP!=null)
{
//IP passed to the function 'scan()'
rslt=InetAddress.getByName(IP);
SCAN(rslt);
}
}
catch(UnknownHostException ee)
{
System.out.println("Error in IP");
}
//waitsfor user input to reuse the scanner or exit
System.out.println("'Y' to reuse || 'N' to exit");
opt=br.readLine();
}
while(opt.equalsIgnoreCase("Y"));
}
//FUNCTION TO SCAN PORTS-----------------------
public static void SCAN(final InetAddress ret)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//port input from user
System.out.println("Enter the Initial limit of port ");
port=Integer.parseInt(br.readLine());
System.out.println("Enter the end limit of port");
limit=Integer.parseInt(br.readLine());
//ticks the start time to calculate total time taken for scanning
start=System.currentTimeMillis();
while(port<=limit)
{
try
{
//scans ports
Socket s1=new Socket(ret,port);
s1.setSoTimeout(1000);
System.out.println("Port is listening at port :"+port);
open_ports.add(port);
}
catch(IOException ex)
{
System.out.println("Port is not listening at port :"+port);
}
port++;
}
//ticks the end time to calculate total time taken for scanning
stop=System.currentTimeMillis();
//function port info is called
PORTINFO();
}
//FUNCTION TO SHOW ALL IFORMATION REGARDING PORTS-----------------------
public static void PORTINFO()
{
System.out.println("______________________________\n");
timetaken=((stop-start)/1000);
System.out.println("Ports Scanned :"+(port-1));
System.out.println("Time Taken to scan :"+timetaken+" sec");
System.out.println("No. of Ports Close :"+((port-1)-open_ports.size()));
System.out.println("No. of Ports Open :"+open_ports.size());
System.out.println("______________________________\n");
for(int i=0;i<open_ports.size();i++)
{
System.out.println("[+] Port OPEN :"+open_ports.get(i));
}
System.out.println("______________________________\n");
}
}