Results 1 to 8 of 8
Thread: Ports being used by a service
- 03-06-2012, 04:24 PM #1
Senior Member
- Join Date
- Nov 2011
- Posts
- 116
- Rep Power
- 0
- 03-06-2012, 05:52 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Ports being used by a service
You could use JNI (or a library that use it) and use system services/files e.g. /etc/services
Or if you have access to the internet you could ask IANA :D
Java Code:URL iana = new URL("http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml"); int port = 80; String protocol = "tcp"; DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = db.parse(iana.openStream()); XPathExpression expr = XPathFactory.newInstance().newXPath().compile("//record[number="+port+" and protocol='"+protocol+"']/name"); //or/and description ... Node name = (Node) expr.evaluate(doc, XPathConstants.NODE); System.out.println(name.getTextContent()); //http
- 03-06-2012, 06:51 PM #3
Senior Member
- Join Date
- Nov 2011
- Posts
- 116
- Rep Power
- 0
Re: Ports being used by a service
Oh I see. Thanks. But what this is doing is, searching the web for the ports that can be used by services?
What Im trying to do is to determine what opened ports are being used by what services on the local system. Because im only scanning my computer's ports, not remote computers.
Thanks
- 03-06-2012, 07:07 PM #4
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Ports being used by a service
its already clear to me, but about what services are you talking about? Well known ports? User ports? Dynamic ports? :D"what opened ports are being used by what services on the local system. Because im only scanning my computer's ports, not remote computers"
- 03-06-2012, 07:25 PM #5
Senior Member
- Join Date
- Nov 2011
- Posts
- 116
- Rep Power
- 0
Re: Ports being used by a service
Hm I suppose all ports :D. Like all tcp and udp ports ranging from 1-65535. If you open up the command prompt and type in 'netstat -an', you will see all ports which are opened, and they are the ports that I'd like to find what services are using those ports?
Thanks
- 03-07-2012, 09:43 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Re: Ports being used by a service
It is likely (unless there's a handy package somewhere in Java) that you'll have to do a Runtime.exec() using that command and then read the process stream to see what's returned. That might also be quicker than trying to find a proper Java package.
Please do not ask for code as refusal often offends.
- 03-07-2012, 01:05 PM #7
Senior Member
- Join Date
- Nov 2011
- Posts
- 116
- Rep Power
- 0
Re: Ports being used by a service
Oh yes, I actually have a method to take command String arguments which uses the command line and outputs the result in java. So I can use the command 'taskkill' to kill processes by their PID. But the porblem is, I dont know how to find out what ports they have opened? If I can find that command(s) to do so, that should be happy days :)
Thanks
- 03-07-2012, 01:09 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Similar Threads
-
Ports
By dougie1809 in forum NetworkingReplies: 2Last Post: 02-17-2012, 10:15 PM -
is success view so I need to change ports on netbeans of the web service
By lse123 in forum NetBeansReplies: 3Last Post: 07-06-2010, 10:15 PM -
Socket's ports
By Rose88 in forum NetworkingReplies: 5Last Post: 05-31-2010, 09:21 PM -
how to call service method inside another service
By kirtichopra2003 in forum Web FrameworksReplies: 1Last Post: 10-24-2009, 02:19 AM -
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