Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"sic transit discus mundi" (From the System Administrator's Guide, by Lars Wirzenius)


devel / comp.lang.java.programmer / what thread or module is listening on a port?

SubjectAuthor
* what thread or module is listening on a port?Andreas Leitgeb
+* Re: what thread or module is listening on a port?Eric Sosman
|`- Re: what thread or module is listening on a port?Martin Gregorie
`* Re: what thread or module is listening on a port?Arne Vajhøj
 +- Re: what thread or module is listening on a port?Andreas Leitgeb
 `- Re: what thread or module is listening on a port?Daniele Futtorovic

1
what thread or module is listening on a port?

<slrnt1cajr.3vsm.avl@logic.at>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=73&group=comp.lang.java.programmer#73

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: avl@logic.at (Andreas Leitgeb)
Newsgroups: comp.lang.java.programmer
Subject: what thread or module is listening on a port?
Date: Wed, 23 Feb 2022 12:37:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <slrnt1cajr.3vsm.avl@logic.at>
Reply-To: avl@logic.at
Injection-Date: Wed, 23 Feb 2022 12:37:15 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="bcd337635f558dc41b38605fea9496f4";
logging-data="16486"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19s+pR1WGBsqhBGnMyMYcm5"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:igxH8y0E0C9E+Upq39dSiJdGF8w=
 by: Andreas Leitgeb - Wed, 23 Feb 2022 12:37 UTC

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)

Re: what thread or module is listening on a port?

<sv5l5b$utj$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=74&group=comp.lang.java.programmer#74

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: esosman@comcast-dot-net.invalid (Eric Sosman)
Newsgroups: comp.lang.java.programmer
Subject: Re: what thread or module is listening on a port?
Date: Wed, 23 Feb 2022 10:51:06 -0500
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <sv5l5b$utj$1@dont-email.me>
References: <slrnt1cajr.3vsm.avl@logic.at>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 23 Feb 2022 15:51:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f342329e37c735a2fe25875023ce23cb";
logging-data="31667"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fQ68kO4/WFDvmdTHhkGX9"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:6Eept0RV33LXjAhagrK7ytYAWjY=
In-Reply-To: <slrnt1cajr.3vsm.avl@logic.at>
Content-Language: en-US
 by: Eric Sosman - Wed, 23 Feb 2022 15:51 UTC

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
> [...]
Not a Java answer, but: Could you use dtrace to watch the
port creations as they go by and see which piece of code
instigates each one? (My Solaris days are a distant memory
and my dtrace skills were never super-keen, but it seems to
me dtrace ought to be able to do the trick.)

If the process opens ten thousand ports this could get
tedious, but still ...

--
esosman@comcast-dot-net.invalid
Look on my code, ye Hackers, and guffaw!

Re: what thread or module is listening on a port?

<sv5on5$qcn$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=75&group=comp.lang.java.programmer#75

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: martin@mydomain.invalid (Martin Gregorie)
Newsgroups: comp.lang.java.programmer
Subject: Re: what thread or module is listening on a port?
Date: Wed, 23 Feb 2022 16:51:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <sv5on5$qcn$1@dont-email.me>
References: <slrnt1cajr.3vsm.avl@logic.at> <sv5l5b$utj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 23 Feb 2022 16:51:49 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="59988af8af5638b0750a6fe386181b43";
logging-data="27031"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197KxQrM/QdRwv6Kdye0RlJWfQ3VLTkVCM="
User-Agent: Pan/0.149 (Bellevue; 4c157ba git@gitlab.gnome.org:GNOME/pan.git)
Cancel-Lock: sha1:QehJ/C8Z5IJ2rXf5AbHME1XlB44=
 by: Martin Gregorie - Wed, 23 Feb 2022 16:51 UTC

On Wed, 23 Feb 2022 10:51:06 -0500, Eric Sosman 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
>> [...]
> Not a Java answer, but: Could you use dtrace to watch the
> port creations as they go by and see which piece of code instigates each
> one? (My Solaris days are a distant memory and my dtrace skills were
> never super-keen, but it seems to me dtrace ought to be able to do the
> trick.)
>
> If the process opens ten thousand ports this could get
> tedious, but still ...

Try "lsof -p processid". Once the process has initialised and opened
files and sockets etc, at the very least you'll get a list of what types
of files have been opened and a fair idea of what each is attached to.

This is UNIX/Linux advice: I don't use Windows at all.

Re: what thread or module is listening on a port?

<62166ba8$0$702$14726298@news.sunsite.dk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=76&group=comp.lang.java.programmer#76

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!news.neodome.net!news.uzoreto.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Date: Wed, 23 Feb 2022 12:15:19 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Subject: Re: what thread or module is listening on a port?
Content-Language: en-US
Newsgroups: comp.lang.java.programmer
References: <slrnt1cajr.3vsm.avl@logic.at>
From: arne@vajhoej.dk (Arne Vajhøj)
In-Reply-To: <slrnt1cajr.3vsm.avl@logic.at>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 87
Message-ID: <62166ba8$0$702$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: 35ceb92c.news.sunsite.dk
X-Trace: 1645636521 news.sunsite.dk 702 arne@vajhoej.dk/68.9.63.232:59667
X-Complaints-To: staff@sunsite.dk
 by: Arne Vajhøj - Wed, 23 Feb 2022 17:15 UTC

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

Re: what thread or module is listening on a port?

<slrnt1g3nq.6b8.avl@logic.at>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=77&group=comp.lang.java.programmer#77

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: avl@logic.at (Andreas Leitgeb)
Newsgroups: comp.lang.java.programmer
Subject: Re: what thread or module is listening on a port?
Date: Thu, 24 Feb 2022 23:04:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <slrnt1g3nq.6b8.avl@logic.at>
References: <slrnt1cajr.3vsm.avl@logic.at>
<62166ba8$0$702$14726298@news.sunsite.dk>
Reply-To: avl@logic.at
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 24 Feb 2022 23:04:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ec49154c737c86885e3e3b41ff8d26ec";
logging-data="24547"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OykMWTHhvTNfs2YkCJsC2"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:s3OjZQ6MVxk2t+Zl4MGDpsjuGlw=
 by: Andreas Leitgeb - Thu, 24 Feb 2022 23:04 UTC

Arne Vajhøj <arne@vajhoej.dk> wrote:
> You could track all locations opening a socket.
> Demo:
> [snip]

Thanks! That looks very promising - will try.

Eric & Martin: thanks for your hints, but unfortunately "lsof" no
longer works on Solaris 11.4 - apparently some API was changed, and
the lsof guys are not willing to bring back that thrown stick.

Even if it did, then it would probably still take some more tricks to
determine the thread-id and translate it into the names of the classes
that this thread is running....

Re: what thread or module is listening on a port?

<t14fsa$6e0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=84&group=comp.lang.java.programmer#84

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: da.futt.news@laposte-dot-net.invalid (Daniele Futtorovic)
Newsgroups: comp.lang.java.programmer
Subject: Re: what thread or module is listening on a port?
Date: Sat, 19 Mar 2022 12:47:23 +0100
Organization: A noiseless patient Spider
Lines: 96
Message-ID: <t14fsa$6e0$1@dont-email.me>
References: <slrnt1cajr.3vsm.avl@logic.at>
<62166ba8$0$702$14726298@news.sunsite.dk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 19 Mar 2022 11:47:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d143705c46d427dee669cadbf300d9e0";
logging-data="6592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hHva8wMU0eMgGpWKaXo97"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:b8eYQvGaa11YPhnSZ3pp2TQPuYo=
In-Reply-To: <62166ba8$0$702$14726298@news.sunsite.dk>
Content-Language: en-US
 by: Daniele Futtorovic - Sat, 19 Mar 2022 11:47 UTC

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.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor