Listening to Ports?

trying to listen on a specific port and log all the data to a text fil

Page 1 of 1

13 Replies - 10710 Views - Last Post: 15 June 2009 - 11:08 PM Rate Topic: -----

#1 sn3twork   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 09

Listening to Ports?

Posted 07 June 2009 - 01:58 AM

Okay, so I am trying to specifically listen on port 53 to try and gather dns requests sent to myself.
I edited my network config to specify myself as my own dns server.

However I don't know how this would work, would my browser connect as a client to me on port 53?
When I go to request a website through my browser no kind of connection is sent to port 53 on my machine.

here is the code I have written so far

The PortListener class is dependent on another class I wrote LogWriter

PortListener

import java.io.*;
import java.net.*;

public class PortListener
{
   ServerSocket listenSocket = null;
   BufferedReader in = null;
   LogWriter logFile;
   String line = "";
   Socket dataSocket = null;
   public PortListener(String logFilePath, int listeningPort) throws IOException, UnknownHostException
   {
	   logFile = new LogWriter(logFilePath);
	   listenSocket = new ServerSocket(listeningPort);

   }
   
   public void Listen() throws IOException, SocketException
   {
	   dataSocket = listenSocket.accept();
	   in = new BufferedReader(new InputStreamReader(dataSocket.getInputStream()));
	   while(true)
	   {
		   if(in.readLine() != null)
			{
			   line = in.readLine();
			   logFile.writeLine(line);
			}
	   }
	   
   }
}




LogWriter


import java.io.*;
public class LogWriter
{
	File logFile;
	FileWriter logWriter;
	public LogWriter(String LogFileDestination) throws IOException
	{
		logFile = new File(LogFileDestination);
		if(!logFile.exists())
		 {
		   logFile.createNewFile();
		 }
		logWriter = new FileWriter(logFile);
	}
	
	public void writeLine(String newLine) throws IOException
	{
		logWriter.write(newLine);
		logWriter.close();
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Listening to Ports?

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Listening to Ports?

Posted 07 June 2009 - 09:04 PM

I guess you have a

PortListener pl = new PortListener("file.log, 53);
pl.listen();

somewhere ?
Was This Post Helpful? 0
  • +
  • -

#3 sn3twork   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 09

Re: Listening to Ports?

Posted 08 June 2009 - 07:24 AM

View Postpbl, on 7 Jun, 2009 - 08:04 PM, said:

I guess you have a

PortListener pl = new PortListener("file.log, 53);
pl.listen();

somewhere ?




yea.. the ide im using im just creating the objects and manually calling the listen method.
Was This Post Helpful? 0
  • +
  • -

#4 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Listening to Ports?

Posted 08 June 2009 - 06:05 PM

just put some System.out.println() in your Listen() method and see what happens
Was This Post Helpful? 0
  • +
  • -

#5 sn3twork   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 09

Re: Listening to Ports?

Posted 08 June 2009 - 08:43 PM

View Postpbl, on 8 Jun, 2009 - 05:05 PM, said:

just put some System.out.println() in your Listen() method and see what happens



I did at one point it doesn't get past the accept method waiting for a connection to the server socket.

View Postpbl, on 8 Jun, 2009 - 05:05 PM, said:

just put some System.out.println() in your Listen() method and see what happens



I did at one point it doesn't get past the accept method waiting for a connection to the server socket.
Was This Post Helpful? 0
  • +
  • -

#6 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Listening to Ports?

Posted 09 June 2009 - 04:29 PM

Does your client writes \n at the end of every line ?
You read lines not byte as usual socket reader do
Was This Post Helpful? 1
  • +
  • -

#7 sn3twork   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 09

Re: Listening to Ports?

Posted 10 June 2009 - 12:04 PM

View Postpbl, on 9 Jun, 2009 - 03:29 PM, said:

Does your client writes \n at the end of every line ?
You read lines not byte as usual socket reader do



when i set breaks in my code, I see that it pauses at the accept method because its never getting a connection. Maybe I am missing something as to how the dns protocol works?

it doesnt even get to read in lines or bytes of data at all.
Was This Post Helpful? 0
  • +
  • -

#8 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Listening to Ports?

Posted 10 June 2009 - 06:08 PM

I guess you will have to show us your client code
Was This Post Helpful? 0
  • +
  • -

#9 sn3twork   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 09

Re: Listening to Ports?

Posted 12 June 2009 - 12:03 PM

View Postpbl, on 10 Jun, 2009 - 05:08 PM, said:

I guess you will have to show us your client code



Then I guess you better get to downloading the source code of firefox...

I swear the people on these forums are just retarded or something.
Was This Post Helpful? 0
  • +
  • -

#10 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Listening to Ports?

Posted 12 June 2009 - 05:22 PM

View Postsn3twork, on 12 Jun, 2009 - 11:03 AM, said:

View Postpbl, on 10 Jun, 2009 - 05:08 PM, said:

I guess you will have to show us your client code



Then I guess you better get to downloading the source code of firefox...

I swear the people on these forums are just retarded or something.

If your client is Firefox I doubt it adds a \n to its request only a newbie wouldn't read the socket by lines rather than by byte so they can react more quickly to html format changes
Was This Post Helpful? 0
  • +
  • -

#11 sn3twork   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 09

Re: Listening to Ports?

Posted 12 June 2009 - 06:58 PM

View Postpbl, on 12 Jun, 2009 - 04:22 PM, said:

View Postsn3twork, on 12 Jun, 2009 - 11:03 AM, said:

View Postpbl, on 10 Jun, 2009 - 05:08 PM, said:

I guess you will have to show us your client code



Then I guess you better get to downloading the source code of firefox...

I swear the people on these forums are just retarded or something.

If your client is Firefox I doubt it adds a \n to its request only a newbie wouldn't read the socket by lines rather than by byte so they can react more quickly to html format changes



either way that does not matter yet, and i can fix that. Like I have said the problem is that it hangs on the accept method which is part of the standard java api. And the accept method waits until a connection request is sent to the port it is listening on. As far as I know the dns protocol runs on port 53 and i cant think of any other way i could listen to port 53 and wait for a connection to occur other than the accept method of the serversocket class.

is there a way i could just capture all the data sent to that port?
Was This Post Helpful? 0
  • +
  • -

#12 sn3twork   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 09

Re: Listening to Ports?

Posted 12 June 2009 - 07:09 PM

View Postpbl, on 12 Jun, 2009 - 04:22 PM, said:

View Postsn3twork, on 12 Jun, 2009 - 11:03 AM, said:

View Postpbl, on 10 Jun, 2009 - 05:08 PM, said:

I guess you will have to show us your client code



Then I guess you better get to downloading the source code of firefox...

I swear the people on these forums are just retarded or something.

If your client is Firefox I doubt it adds a \n to its request only a newbie wouldn't read the socket by lines rather than by byte so they can react more quickly to html format changes



either way that does not matter yet, and i can fix that. Like I have said the problem is that it hangs on the accept method which is part of the standard java api. And the accept method waits until a connection request is sent to the port it is listening on. As far as I know the dns protocol runs on port 53 and i cant think of any other way i could listen to port 53 and wait for a connection to occur other than the accept method of the serversocket class.

is there a way i could just capture all the data sent to that port?
Was This Post Helpful? 0
  • +
  • -

#13 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Listening to Ports?

Posted 12 June 2009 - 07:58 PM

View Postsn3twork, on 12 Jun, 2009 - 06:09 PM, said:

is there a way i could just capture all the data sent to that port?

just listen to it
but as we are just retarded or something we don't share our receipes :D
Was This Post Helpful? 0
  • +
  • -

#14 sn3twork   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 09

Re: Listening to Ports?

Posted 15 June 2009 - 11:08 PM

View Postpbl, on 12 Jun, 2009 - 06:58 PM, said:

View Postsn3twork, on 12 Jun, 2009 - 06:09 PM, said:

is there a way i could just capture all the data sent to that port?

just listen to it
but as we are just retarded or something we don't share our receipes :D




recipes*

READ THIS FIRST:


2. Use proper English. Correct grammar and spelling is required.

View Postpbl, on 12 Jun, 2009 - 06:58 PM, said:

View Postsn3twork, on 12 Jun, 2009 - 06:09 PM, said:

is there a way i could just capture all the data sent to that port?

just listen to it
but as we are just retarded or something we don't share our receipes :D



and how would i "just listen to it" ? give me some kind of guidance as to what class or package.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1