[sdnog] sniffing the network by using JNetPcap

Israa Eltayeb israa19944 at gmail.com
Wed Oct 19 11:47:07 SAST 2016


Salam,
Can I use wireshark tool for sniffing GSM network ?
Kind regards :)

On 19 Oct 2016 09:48, "Khadiga Elhassan" <okhadiga76 at gmail.com> wrote:

> Dear Aya:
> good morning ,
>  there is another tool for sniffing network is called WIRESHARK and it is
> very easy to use and can be adjusted  according to your need ,you can try
> it if you wish
>
> khadiga
>
> On Sat, Oct 15, 2016 at 2:23 PM, AYA FATHI <faya862 at gmail.com> wrote:
>
>> Hi all :)
>>
>> Am trying to write  code sniffing the network by using JNetPcap lib on
>> eclipse
>>
>> while running the code their is no error but its not capturing any thing
>>
>> any help
>>
>> the code as show below
>>
>>
>>
>> import java.util.ArrayList;
>>
>> import java.util.Date;
>>
>> import java.util.List;
>>
>> import java.util.Queue;
>>
>> import java.util.concurrent.ArrayBlockingQueue;
>>
>>
>>
>> import org.jnetpcap.ByteBufferHandler;
>>
>> import org.jnetpcap.Pcap;
>>
>> import org.jnetpcap.PcapHeader;
>>
>> import org.jnetpcap.PcapIf;
>>
>> import org.jnetpcap.packet.PcapPacket;
>>
>> import org.jnetpcap.packet.PcapPacketHandler;
>>
>>
>>
>>
>>
>> public class  wer {
>>
>>
>>
>>
>>
>>     public static void main(String[] args) {
>>
>>         List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled
>> with NICs
>>
>>         StringBuilder errbuf = new StringBuilder(); // For any error msgs
>>
>>
>>
>>
>>         int r = Pcap.findAllDevs(alldevs, errbuf);
>>
>>
>>
>>         if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
>>
>>             System.err.printf("Can't read list of devices, error is %s",
>> errbuf
>>
>>                 .toString());
>>
>>             return;
>>
>>         }
>>
>>
>>
>>         System.out.println("Network devices found:");
>>
>>
>>
>>         int i = 0;
>>
>>         for (PcapIf device : alldevs) {
>>
>>             String description = (device.getDescription() != null) ?
>> device.getDescription() : "No description available";
>>
>>             System.out.printf("#%d: %s [%s]\n", i++, device.getName(),
>> description);
>>
>>         }
>>
>>
>>
>>         PcapIf device = alldevs.get(3); // We know we have atleast 1
>> device
>>
>>
>>
>>         System.out.printf("\nChoosing '%s' on your behalf:\n",
>> (device.getDescription() != null) ? device.getDescription()  :
>> device.getName());
>>
>>
>>
>>         /***********************************************************
>> ****************
>>
>>          * Second we open up the selected device
>>
>>          **************************************************************************/
>>
>>
>>         int snaplen =  2048;           // Capture all packets, no
>> trucation
>>
>>         int flags =  Pcap.MODE_PROMISCUOUS; // capture all packets
>>
>>         int timeout = 60 * 10000;           // 10 seconds in millis
>>
>>
>>
>>          Pcap pcap = Pcap.openLive(device.getName(), snaplen, flags,
>> timeout, errbuf);
>>
>>          if (pcap == null) {
>>
>>              System.err.printf("Error while opening device for capture: "
>>
>>
>>                  + errbuf.toString());
>>
>>              return;
>>
>>          }
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>         PcapPacketHandler<String> jpacketHandler = new
>> PcapPacketHandler<String>() {
>>
>>
>>
>>             public void nextPacket(PcapPacket packet, String user) {
>>
>>
>>
>>                 System.out.printf("Received packet at %s caplen=%-4d
>> len=%-4d %s\n",
>>
>>                     new Date(packet.getCaptureHeader().timestampInMillis()),
>>
>>
>>                     packet.getCaptureHeader().caplen(),  // Length
>> actually captured
>>
>>                     packet.getCaptureHeader().wirelen(), // Original
>> length
>>
>>                     user                                 // User supplied
>> object
>>
>>                     );
>>
>>            System.out.print("\n fine"); }
>>
>>         };
>>
>>
>>
>>         pcap.loop(10, jpacketHandler, "jNetPcap rocks!");
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>        pcap.close();
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>     }
>>
>>
>>
>>
>> }
>>
>> _______________________________________________
>> sdnog mailing list
>> sdnog at sdnog.sd
>> http://lists.sdnog.sd/mailman/listinfo/sdnog
>>
>>
>
>
> --
> Khadiga
>
>
>
> _______________________________________________
> sdnog mailing list
> sdnog at sdnog.sd
> http://lists.sdnog.sd/mailman/listinfo/sdnog
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sdnog.sd/pipermail/sdnog/attachments/20161019/675e808c/attachment.html>


More information about the sdnog mailing list