Which port to sniff for packets

Hi ppl, i been tasked to write a basic packet sniffer program using Java to sniff packets off my school's student LAn for one of my subject's assignment, topic which is on network protocol analysis.
My plan is to write several type of packet classes like TCP,IP,UDP
then i got my own sniffer program which will sniff packets off the LAN , detect type of packet and then instantiate of the above objects and the user can then manipulate.
The GUI and implementation is rather fundamental to me, but i am rather puzzled or loss at how can i actually sniff the packets off the LAN. Is there a specfic class in the Java API, or port number which i can specify that i can capture the packets for analysis ?
Hope you ppl can pump in your suggestions on the capturing data info..
thanks
wilson

The easiest way you could do this is by creating a socket to the computer you want to scan.
Than use the getLocalPort() method and the getPort() method to get the values back.
You could use this script:
import java.net.*;
import java.io.*;
import java.sql.*;
import java.util.*;
public class portListen extends Thread {
   /* Public interface ******************************************************/
   static public void main( String argv[] ) {
      String cPortFrom;
      String cPortDesc;
      System.out.println( "\nOpening portListen.ini ...\n" );
      try {
         RandomAccessFile RAF;
         RAF = new RandomAccessFile("portListen.ini","r");
         String cIPFrom = "127.0.0.1";
         if( argv.length>0 )
            cIPFrom = argv[0];
         String cLine = "";
         cLine = RAF.readLine();
         while( cLine!=null ){
            StringTokenizer token = new StringTokenizer( cLine, "," );
            cPortFrom="";
            cPortDesc="";
            if( token.hasMoreTokens() )
               cPortFrom = token.nextToken();
            if( token.hasMoreTokens() )
               cPortDesc = token.nextToken();
            if( cPortFrom.length()>0 ){
               portListen server = new portListen( cIPFrom, cPortFrom, cPortDesc );
               server.start();
            cLine = RAF.readLine();
         RAF.close();
         System.out.println( "\nAll system ready" );
      } catch(Exception e) {
         e.printStackTrace();
         System.out.println( "\nError during opening of portListen.ini  " +e.toString() );
   private int nPortFrom;
   private String cInServer;
   private String cPortDesc;
   public portListen( String cIPFrom, String inPort, String cPDesc ){
      cInServer  = cIPFrom;
      nPortFrom  = Integer.parseInt(  inPort );
      cPortDesc  = cPDesc;
      System.out.println( "   listen [" +cInServer +":" +nPortFrom +":" +cPortDesc +"] " );
   public void run(){
      try {                                  // port, maxrequest, address
         ServerSocket sock = new ServerSocket( nPortFrom, 5, InetAddress.getByName(cInServer) );
         while( true ){
            Socket socket = sock.accept();
            //System.out.println( " User at [" +socket.getLocalPort() +":" +cPortDesc +"] retreive information" );
            System.out.println( " New user from [" +socket.getInetAddress() +":" +socket.getPort() +"] to [" +socket.getLocalAddress()  +":" +socket.getLocalPort() +":" +cPortDesc +"]" );
            socket.close();
      } catch (Throwable e) {
         e.printStackTrace();
         System.out.println( e.getMessage() );
         System.out.println( "Error in listen [" +nPortFrom +"] " );
}I got this code from this url: http://www.baccan.it/index.php?sezione=javaportlistener&email=si
Hope this helps you out a bit. Good luck.

Similar Messages

  • Which port is open for connection ?

    how could I know which port is open for connection ?
    In the java, I use JDBC to connect to Oracle,
    connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:sid", "scott","tiger");Do we have a command to show open port ?
    Thanks.

    What is your Oracle version, and do you use dedicated connections or "shared servers"? From your port number invoked (1521), I'll guess you use dedicated connections. In that case, the listener (located at 1521) will "spawn" a dedicated process for your session, and tell this process to start on another port (usually falling on a certain range, depending on your OS). An easy way to see this would probably to turn listener tracing on. Here's what I found in the log file after I started a new (dedicated) session on my 10.2 DB:
    "22-OCT-2006 21:31:16 * (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ora102)(CLIENT_REGISTRATION=ora102)(CID=(PROGRAM=C:\oracle92\bin\sqlplusw.exe)(HOST=DANIELROYLAPTOP)(USER=Daniel))(CLIENT_REGISTRATION=ora102)) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=3198)) * establish * ora102 * 0"
    HTH
    Daniel

  • Which ports oracle use for replication..

    Hi All,
    I want to know which ports orcale use for replication.plz reply me quickly.
    Thanx in advance

    This is configurable. By default, listeners will run on port 1521, but sites can specify multiple and/or different ports. Depending on the OS of the database, connections made on that initial port may be redirected to a different port (Windows) or may do all the communication on the listener port (Unix). Windows databases can be configured to do all communication on the listener port, though there may be a performance impact to doing so.
    Justin

  • Which port need open for Imoprt WS in to the TREE ??

    ZfD6.5SP2.
    WS----firewall-------NW_SERVER
    Which ports ned open on the firewall for import Ws in to the TREE ??
    Serg

    Serg,
    >Which ports ned open on the firewall for import Ws in to the TREE ??
    8039
    Jared Jennings
    Data Technique, Inc.
    Novell Support Forums Sysop
    http://wiki.novell.com

  • Which ports are involved for ACS-ACS DB synchronisation ?

    Hi all,
    which ports are used when one ACS is pushing its database to another ACS ?

    With ACS v4.x its port 2000.

  • Which port to use for the peer-keep alive

    Hi All,
    We have 2 Nexus 6001s in our data center.
    The management port of each 6001 is connected to the other and this link is used as the peer keep alive link.
    My colleague is suggesting that we use one of the inline data ports as the keep alive link.
    Can you please advise on the pros and cons of using management/inline port as keep live link and the best practise to follow in this case?
    Thanks,
    Pete

    Hi Pete,
    Here are the best recommendation in order of preference.
    1. Use mgmt0 (along with management traffic)
         * Pros: whats good on this option is you are totally separating the VPC Peer keepalive link on another VRF (management) and does not mingle with the data or global vrf..
         * Cons: VPC PKL is dependent on the OOB management switch.
    2. Use dedicated 1G/10GE front panel ports. 
        * Pros - can just be a direct link between the N6K pair and not dependent on other boxes. 
        * Cons - you need extra SFPs for VPC PKL while the VPC PKL traffic join the global VRF.
    HTH
    Jay Ocampo

  • Which ports are needed for SAP HANA Studio - HANA DB communication?

    I want to connect SAP HANA Studio to a HANA instance. The HANA instance number is 40.
    The SAP note 1592925 states that the ports 5$$13/5$$14 and 3$$15 should be open to allow communication between the HANA Studio and the HANA database. I even see the instance in the HANA Studio, but I cannot administrate it and the HANA studio gives this general "I don't want you to know what the error actually is" message:
    !ENTRY com.sap.ndb.studio.navigator 4 1 2012-01-16 14:01:40.627
    !MESSAGE [HDB hostname 40 (SYSTEM)] Error on refreshing system
    !SUBENTRY 1 com.sap.ndb.studio.navigator 4 0 2012-01-16 14:01:40.627
    !MESSAGE SAPControl request failed
    !STACK 0
    com.sap.ndb.studio.sapcontrol.SAPControlException: SAPControl request failed
         at com.sap.ndb.studio.sapcontrol.operations.SAPControlOperation.execute(SAPControlOperation.java:118)
         at com.sap.ndb.studio.sapcontrol.SAPControl.getInstanceProperties(SAPControl.java:439)
         at com.sap.ndb.studio.sapcontrol.SAPControl.collectProperties(SAPControl.java:466)
         at com.sap.ndb.studio.sapcontrol.SAPControl.open(SAPControl.java:297)
         at com.sap.ndb.studio.sapcontrol.SAPControlManager.getSAPControl(SAPControlManager.java:108)
         at com.sap.ndb.studio.sapcontrol.SAPControlManager.getSAPControl(SAPControlManager.java:81)
         at com.sap.ndb.studio.sapcontrol.SAPControlManager.needCredentials(SAPControlManager.java:57)
         at com.sap.ndb.studio.navigator.operations.SAPSystemObjectUpdate.executeTrySAPControl(SAPSystemObjectUpdate.java:102)
         at com.sap.ndb.studio.navigator.operations.SAPSystemObjectUpdate.execute(SAPSystemObjectUpdate.java:63)
         at com.sap.ndb.studio.navigator.operations.UpdateSAPSystemOperation.execute(UpdateSAPSystemOperation.java:75)
         at com.sap.ndb.studio.datamodel.controler.DataModelOperation.execute(DataModelOperation.java:67)
         at com.sap.ndb.studio.datamodel.controler.DataModelOperationQueue$DataModelOperationThread.run(DataModelOperationQueue.java:99)
    Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
         at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source)
         at com.sap.ndb.studio.sapcontrol.operations.SAPControlOperation.execute(SAPControlOperation.java:94)
         ... 11 more
    Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
         at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source)
         ... 13 more
    Caused by: java.net.ConnectException: Connection refused: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(Unknown Source)
         at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
         at java.net.PlainSocketImpl.connect(Unknown Source)
         at java.net.SocksSocketImpl.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at sun.net.NetworkClient.doConnect(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.<init>(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
         ... 14 more
    Do I need to open any other ports to make HANA Studio work with HANA DB?
    Regards,
    Mark

    Hi Mark,
    The HANA Studio connects to HANA DB Instance with JDBC on port 3<Instance number>15.
    For your HDB with Instance Number 40, the port would be 34015.
    HANA Studio will automatically assign the JDBC port number when you assign the instance number when you add new system.
    Looking at the error message that you posted:
    !ENTRY com.sap.ndb.studio.navigator 4 1 2012-01-16 14:01:40.627
    !MESSAGE [HDB hostname 40 (SYSTEM)] Error on refreshing system
    It looks like the hostname entry was not entered correctly (you might have entered "hostname" value when adding the system in HANA Studio).
    Here is an example of correct log entry on DCA database instance on hanasvr-01 server with Instance number 00:
    !ENTRY com.sap.ndb.studio.navigator 4 1 2012-01-10 13:55:23.598
    !MESSAGE [DCA hanasvr-01 00 (SYSTEM)]
    You may want to delete and re-add your HDB instance in your HANA Studio.
    Regards,
    Ferry

  • Which ports need open for:...

    Ws(xp_prof)+BM39VPNclient-----NAT1---INTERNET---NAT2----BM39---PRIVETLAN
    USer work with Ws - Xp_prof_SP2. On this Xp installe BM39 VPN Client.
    Between WS and INETRNET - NAT1 (iptables).
    On the other side:
    INTERNET--->NAT2---->BM39SERVER---->PRIVETLAN
    I ask:
    Whic ports and protocols (and in whic directions) need open in the NAT1
    for Allow VPN connection between WS and BM39 in this configuration.
    Serg

    On Sat, 09 Feb 2008 12:55:40 +0000, mysterious wrote:
    > serg wrote:
    >> Ws(xp_prof)+BM39VPNclient-----NAT1---INTERNET---NAT2----BM39---PRIVETLAN
    >>
    >> USer work with Ws - Xp_prof_SP2. On this Xp installe BM39 VPN Client.
    >>
    >> Between WS and INETRNET - NAT1 (iptables).
    >>
    >> On the other side:
    >> INTERNET--->NAT2---->BM39SERVER---->PRIVETLAN
    >>
    >> I ask:
    >> Whic ports and protocols (and in whic directions) need open in the NAT1
    >> for Allow VPN connection between WS and BM39 in this configuration.
    >>
    >> Serg
    >>
    >>
    > tid10088980
    Thank you.
    Serg

  • Which ports to open for registering an iPod Touch OTA via proxy / firewall ?

    I need to set up  some iPod Touch over the air via a wifi network controlled with a firewall. I get a message "unable to connect registration server". I suppose I have to open ports, but which ones ??

    Try here:
    http://support.apple.com/kb/ts3297
    http://support.apple.com/kb/TS3125

  • Which ports are required by ODMA?

    I am an SAP R/3 administrator.
    I want to upgrade from Oracle 8.0.6.3 to 8.1.7.3 under AIX 4.3.3
    So I need to use the RUNINSTALLER followed by the ODMA
    I want to do this remotely, passing out through one firewall then in through another.
    My X-emulation is ReflectionX, for which I already have firewall transparency for port 6000 .
    My question: Which ports are required for RUNINSTALLER + ODMA
    Thanks in advance,
    Keith

    Hi Keith!
    This forum deals with issues specifically related to the Oracle Migration Workbench product. This product is used to migrate non Oracle databases to Oracle8i & Orace9i. (It does not enable you to migrate from one Oracle database version to another!)
    In order to get assistance in performing a migration frrm one Oracle database version to another you should contact Oracle RDBMS Support. You should be able to find their contact details in the Documentation that comes with ODMA.
    hope this helps
    - Garry

  • Which ports are used by LMS 4.2.5 Software Center

    Hi everybody!
    we are trying to download device updates and packages via the software center of lms 4.2.5. but get the attached error msg.
    Which ports are used for the download (for firewall configuration)
    I can't find the used ports for this function in the install guide.....
    I am very thankful for any suggestions!
    Edit:
    here is the log output:
    [ Sun Jan 04 00:30:01 CET 2015 ] ERROR  [CcoDownloadAdapter : getXmlFileList]  : failed to connect to Cisco.com:RespCode=302, RespMsg=Found
    [ Sun Jan 04 00:30:01 CET 2015 ] INFO   [SecurityHandler : getCSProxyHost]  : No proxy Host configured
    [ Sun Jan 04 00:30:01 CET 2015 ] INFO   [SecurityHandler : getCSProxyPort]  : No proxy port confgured
    [ Sun Jan 04 00:30:01 CET 2015 ] ERROR  [CcoDownloadAdapter : getXmlFileList]  : failed to connect to Cisco.com:RespCode=302, RespMsg=Found
    [ Mon Jan 05 00:30:01 CET 2015 ] ERROR  [CcoDownloadAdapter : getXmlFileList]  : failed to connect to Cisco.com:RespCode=302, RespMsg=Found
    [ Mon Jan 05 00:30:01 CET 2015 ] INFO   [SecurityHandler : getCSProxyHost]  : No proxy Host configured
    [ Mon Jan 05 00:30:01 CET 2015 ] INFO   [SecurityHandler : getCSProxyPort]  : No proxy port confgured
    [ Mon Jan 05 00:30:01 CET 2015 ] ERROR  [CcoDownloadAdapter : getXmlFileList]  : failed to connect to Cisco.com:RespCode=302, RespMsg=Found
    there is no proxy in use, so the is none configured :)

    Hi,
    Looks like you are encountering this BUG
    CSCur85172    Unable to installing the device packages from cisco.com using LMS Server
    Try this to resolve the issue::
    Stop Daemon Manager
    2.            Change the protocol 'http' to 'https' for the below URL's in vds.properties
    file located under /NMSROOT/lib/classpath/com/cisco/nm/xms/vds/.
    NGCcoScript=http://tools.cisco.com/software/catalog/swcs/softwaremetadata
    NGCcoImageScript=http://tools.cisco.com/software/catalog/swcs/image
    TO
    NGCcoScript=https://tools.cisco.com/software/catalog/swcs/softwaremetadata
    NGCcoImageScript=https://tools.cisco.com/software/catalog/swcs/image
    3.            Start the Daemon Manager.
    Thanks-
    Afroz
    ****Ratings Encourages Contributors ****

  • HT201300 You have Macbook of some kind and it has two Thunderbolt ports.  Which port do you use first for an external monitor/projector?

    You have Macbook of some kind and it has two Thunderbolt ports.  Which port do you use first for an external monitor/projector?

    By the way, I have tried shutting of the display switching in the power settings.  That was basically the only real answer I found anywhere.  It didn't work.

  • I have a Comcast system and am going through a Bose amp for sound.  The comcast box has an HDMI port which I've used for the Apple TV connection.  Nothing works! Help.

    have a Comcast system and am going through a Bose amp for sound.  The comcast box has an HDMI port which I've used for the Apple TV connection.  Nothing works! Help.

    Thanks.  Thought that would be the solution but for my wall mounted TV it's going to be a problem but many thanks for your reply.....

  • How can I know which IP port is free for use?

    I am doing a internet project that the sender need to send voice at a port and receive the voice from another port.
    I want to assign the port to the send function and receive function automatically, so I want to use some API to determine which port in local machine is free and assign that one for the function.

    If you bind to port 0 the system will assign the next available port to you.

  • Which ports / protocoll are used for pruning the printers from AD on the printserver

    Dear all
    Does anyone know, which ports or protocols are used between DomainController and Printserver to prune the printer-queue's?
    Regards
    Michael

    Print Spooler The Print Spooler system service manages all local and network print queues and controls all print jobs. The print spooler is the center of the Windows printing subsystem and controls all printing jobs. It manages the print queues on the system
    and communicates with printer drivers and input/output (I/O) components, for example, the USB port and the TCP/IP protocol suite.
    System Service Name Spooler
    Application protocol Protocol Port
    NetBIOS Session Service TCP 139
    SMB TCP 445
    http://support.microsoft.com/kb/832017/en-us

Maybe you are looking for