Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39742
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: what thread or module is listening on a port? |
| Date | 2022-03-19 12:47 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <t14fsa$6e0$1@dont-email.me> (permalink) |
| References | <slrnt1cajr.3vsm.avl@logic.at> <62166ba8$0$702$14726298@news.sunsite.dk> |
On 23/02/2022 18:15, Arne Vajhøj wrote:
> On 2/23/2022 7:37 AM, Andreas Leitgeb wrote:
>> Given a java process (that uses a couple of 3rd-party libs and stuff from
>> maven repo) and a TCP port number that this process is listening on
>> (for all
>> interfaces), what options do I have for finding out, which "part" of the
>> process is responsible for the listening port?
>>
>> Once I see, which of the umpty libraries did it, I can look for options
>> to either unconfigure it, bind to localhost, or at least understand it.
>>
>> That's on Solaris (Unix).
>> $ netstat -aun | grep "54157.*LISTEN" # gives me e.g:
>> *.52634 *.* xxx 54157 java 0 0
>> 256000 0 LISTEN
>>
>> The portnumber is in the >32k range and changes with each restart
>> of the process, thus apparently isn't itself configured.
>>
>> When I telnet to the port, the connection is dropped after writing any 6
>> bytes to it. - maybe that rings a bell for some type of common service?
>>
>> PS: Java here is Azul's "Zulu", openjdk version 1.8.0_252
>> (in case it matters for further diagnostic tools available)
>
> You could track all locations opening a socket.
>
> Demo:
>
> package february;
>
> import java.io.IOException;
> import java.lang.reflect.Constructor;
> import java.net.ServerSocket;
> import java.net.SocketImpl;
> import java.net.SocketImplFactory;
> import java.util.Arrays;
> import java.util.stream.Collectors;
>
> public class SocketTrace {
> public static void enableTrace() throws IOException {
> ServerSocket.setSocketFactory(new SocketImplFactory() {
> @Override
> public SocketImpl createSocketImpl() {
> Exception e = new Exception();
> StackTraceElement[] ste = e.getStackTrace();
> String trace = Arrays.stream(ste).skip(4).map(v ->
> v.getClassName() + "." + v.getMethodName()).collect(Collectors.joining("
> "));
> System.out.printf("socket opened from %s\n", trace);
> try {
> Class<?> stdimpl =
> Class.forName("java.net.SocksSocketImpl");
> Constructor<?> ctor =
> stdimpl.getDeclaredConstructor();
> ctor.setAccessible(true);
> return (SocketImpl) ctor.newInstance();
> } catch(Exception ex) {
> throw new RuntimeException(ex);
> }
> }
> });
> }
> public static void m3() throws IOException {
> ServerSocket s = new ServerSocket(12345);
> s.close();
> }
> public static void m2() throws IOException {
> m3();
> }
> public static void m1() throws IOException {
> m2();
> }
> public static void main(String[] args) throws IOException {
> enableTrace();
> m3();
> m2();
> m1();
> }
> }
>
> output:
>
> socket opened from february.SocketTrace.m3 february.SocketTrace.main
> socket opened from february.SocketTrace.m3 february.SocketTrace.m2
> february.SocketTrace.main
> socket opened from february.SocketTrace.m3 february.SocketTrace.m2
> february.SocketTrace.m1 february.SocketTrace.main
>
> Arne
>
That's bloody brilliant!
--
DF.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
what thread or module is listening on a port? Andreas Leitgeb <avl@logic.at> - 2022-02-23 12:37 +0000
Re: what thread or module is listening on a port? Eric Sosman <esosman@comcast-dot-net.invalid> - 2022-02-23 10:51 -0500
Re: what thread or module is listening on a port? Martin Gregorie <martin@mydomain.invalid> - 2022-02-23 16:51 +0000
Re: what thread or module is listening on a port? Arne Vajhøj <arne@vajhoej.dk> - 2022-02-23 12:15 -0500
Re: what thread or module is listening on a port? Andreas Leitgeb <avl@logic.at> - 2022-02-24 23:04 +0000
Re: what thread or module is listening on a port? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2022-03-19 12:47 +0100
csiph-web