Skip to content

Commit 60721c2

Browse files
authored
Add files via upload
1 parent 8e846ee commit 60721c2

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

class/Sniffer.class

3.3 KB
Binary file not shown.

jcap/JpcapSetup-0.7.exe

162 KB
Binary file not shown.

lib/jpcap.jar

26.6 KB
Binary file not shown.

src/Sniffer.java

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Esta clase describe las funcionalidad del objeto Sniffer.
3+
* @package Sniffer
4+
* @subpackage Clases
5+
* @author RR Soluciones IT SAS
6+
* @version 1.0.0
7+
* @copyright 2018
8+
*/
9+
package Sniffer.class;
10+
import java.net.*;
11+
import java.io.*;
12+
import jpcap.JpcapCaptor.*;
13+
import jpcap.JpcapSender;
14+
import jpcap.NetworkInterface.*;
15+
import jpcap.NetworkInterfaceAddress;
16+
import jpcap.packet.*;
17+
18+
class Sniffer{
19+
/**
20+
*@description Variables de la clase
21+
*/
22+
JpcapCaptor captor;
23+
NetworkInterface[] list;
24+
String str,info;
25+
int x, choice;
26+
/**
27+
* @function main
28+
* @param String args
29+
* @description
30+
*/
31+
public static void main(String args[]){
32+
new Sniffer();
33+
}
34+
/**
35+
* @function Sniffer
36+
* @param
37+
* @description Constructor de la clase Sniffer
38+
*/
39+
public Sniffer(){
40+
list = JpcapCaptor.getDeviceList();
41+
System.out.println("Available interfaces: ");
42+
for(x=0; x<list.length; x++){
43+
System.out.println(x+" -> "+list[x].description);
44+
}
45+
choice = Integer.parseInt(obtenerEntrada("Choose interface (0,1..): "));
46+
System.out.println("Listening on interface -> "+list[choice].description);
47+
try{
48+
captor=JpcapCaptor.openDevice(list[choice], 65535, false, 20);
49+
captor.setFilter("ip and tcp", true);
50+
}
51+
catch(IOException ioe){
52+
ioe.printStackTrace();
53+
}
54+
while(true){
55+
Packet info = captor.getPacket();
56+
if(info != null)
57+
System.out.print(obtenerPaquete(info));
58+
}
59+
}
60+
/**
61+
* @function obtenerEntrada
62+
* @param String q
63+
* @description
64+
*/
65+
public static String obtenerEntrada(String q){
66+
String input = "";
67+
System.out.print(q);
68+
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
69+
try{
70+
input = bufferedreader.readLine();
71+
}
72+
catch(IOException ioexception){
73+
}
74+
return input;
75+
}
76+
/**
77+
* @function obtenerEntrada
78+
* @param String q
79+
* @description
80+
*/
81+
String obtenerPaquete(Packet pack){
82+
int i=0,j=0;
83+
byte[] bytes=new byte[pack.header.length + pack.data.length];
84+
System.arraycopy(pack.header, 0, bytes, 0, pack.header.length);
85+
System.arraycopy(pack.data, 0, bytes, pack.header.length, pack.data.length);
86+
StringBuffer buffer = new StringBuffer();
87+
for(i=0; i<bytes.length;){
88+
for(j=0;j<8 && i<bytes.length;j++,i++){
89+
String d = Integer.toHexString((int)(bytes [i] &0xff));
90+
buffer.append((d.length() == 1 ? "0" + d:d ) + " ");
91+
if(bytes[i]<32 || bytes[i]>126)
92+
bytes[i] = 46;
93+
}
94+
}
95+
return new String(bytes,i - j, j);
96+
}
97+
}

0 commit comments

Comments
 (0)