Results 1 to 7 of 7
Thread: Finding Open ports
- 01-06-2009, 01:17 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 4
- Rep Power
- 0
- 01-06-2009, 01:49 AM #2
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
It's possibly not quite what you had in mind, but systems that support the "netstat" command, you can run that in a process, then parse the output.
Neil Coffey
Javamex - Java tutorials and performance info
- 01-11-2009, 05:04 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 13
- Rep Power
- 0
well it is very easy to monitor or scan ports...
u can get that code from any book or net or u tell me i wll give that to u ...
in which u can scan any computers port from any range...:)
- 01-12-2009, 06:18 AM #4
Member
- Join Date
- Dec 2008
- Posts
- 4
- Rep Power
- 0
- 01-12-2009, 07:16 AM #5
http://www.iana.org/assignments/port-numbers
Usually this question has to do with selecting a port number which one can use in one's programs, be they student or real programs.
I recoded this several times and got started on something else, so the range and offset math needs to be verified....
reading it just now, it looks like I revised the code to use java.util.Random ...Java Code:import java.util.Random;// import java.net.*;// /* USE OF THIS CODE CONSTITUTES DISCUSSION OF OPINION IN A TECHNICAL FORUM * NO SUITABILITY FOR ANY USE IS IMPLIED BY READING THE OPINION PROVIDED * * ... the supposed "cost" of synchronization is usually really trivial compared * to the energy people spend trying to avoid it. Because both require invalidating * a cache line and going to main memory for the data, then testing the value of the * variable before returning it. ( Master Wong ) * * Simple client/server Socket selection program: ubb = get_topic & f=8 & t=002898 * Select a port to invoke the public Socket(InetAddress,int port) with. * The Dynamic and/or Private Ports are those from 49152 through 65535 * Source: http://www.iana.org/assignments/port-numbers * The port numbers are divided into three ranges: the Well Known Ports, * the Registered Ports, and the Dynamic and/or Private Ports. */ public class PortSelector extends Socket { private static final Object lock = new Object(); int port;// static final int range = ( 65535 - 49152 );// Private Ports are those from 49152 through 65535 InetAddress nannaBanna;// public static Socket sockitToEm;// /***************** always put some random strings in your code *****************/ /***************** it's more fun that way and makes peole think *****************/ /***************** you know what your are doing. *****************/ java.lang.String a = "06d98abff66495089d23f269cf296b783f5499e8b1b75fabc97e417f5319ba2f"; java.lang.String b = "fffb0d5f946240499dd413202c8567f070d32672ece45f75249164ece47b2c3e"; java.lang.String c = "7b29d40b262212abea99171af1c197835297c17a7361f2a5b371a8146f8340c3"; java.lang.String d = "3657e092450b24d7f3542df00daa7f4a445dbd2baa7064f2bbdd165a7ad16b58"; PortSelector() // { // Call to super() creates an unconnected socket, with the system-default type of SocketImpl. super();// } PortSelector(InetAddress incoming, int suggested) throws java.io.IOException // { // Call to super() creates an unconnected socket, with the system-default type of SocketImpl. super();// if((suggested >= 49152) && (suggested <= 65535)) port = suggested;// if(incoming != null) nannaBanna = incoming;// Random candidatePort = new Random();// if(port == 0){while((((port = candidatePort.nextInt(49152)) + range ) <= 49152) || (port > 65535))continue;}// sockitToEm = new Socket( nannaBanna , port);// } public static synchronized Socket getSocket(){return sockitToEm;} // public static synchronized Integer getPortNumber() { Random candidateInt = new Random();// int cadidatePort = (candidateInt.nextInt(49152) + range); if((cadidatePort < 49152) || (cadidatePort > 65535)) { cadidatePort = (candidateInt.nextInt(49152) + range); } while((cadidatePort < 49152) || (cadidatePort > 65535)); return new Integer(cadidatePort); } // public static void main(String[] args) { System.out.println(new PortSelector().getPortNumber().toString());// } }
Java will not grant much access to ip because of problems from IPv4 spoofing. A given IP address may have any allowable port numbers, an IP adddress is a machine. Port numbers are something programmers can use to keep services and process disentangled.
Code provided gets a port number in the range that the rfc suggests as not allocated to any paticular service.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 01-12-2009, 09:19 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-14-2009, 06:04 PM #7
Member
- Join Date
- Jan 2009
- Posts
- 13
- Rep Power
- 0
port scan
u can just simply make connection using socket with each port..if it makes than that port is not in use otherwise that port is already in use...
for(int i=0;i<65535;i++)
{
try{
Socket sock=new Socket(host,i);
System.out.println("server responding on port no.."+i);
}
catch(IOException e)
{
System.out.println("no server on port no.."+i);
}
catch(UnknownHostException e)
{
}
}
Similar Threads
-
How to scan your computer for ports in use
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 08:13 PM -
Looking for servers on ports
By Java Tip in forum Java TipReplies: 0Last Post: 12-13-2007, 09:28 AM -
javax.comm package for COM ports
By valery in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 03:03 PM -
How to know the ports opened by JVM
By sandeepspatil in forum Advanced JavaReplies: 1Last Post: 08-02-2007, 01:51 PM -
Ports In Java
By Peter in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 06:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks