Oshi: How to like the same "sigar" get TCP and UDP connection tables?

Created on 18 Jan 2017  路  8Comments  路  Source: oshi/oshi

How to like the same "sigar" get TCP and UDP connection tables?

question

All 8 comments

This looks like it's possible to grab parsing the netstat output with various switches. I am not sure how consistent this is cross-platform, however.

@dbwiddis 'sigar' library By native libraries,dll,so,etc.

OSHI is not SIGAR. We don't write and install native DLLs. If you can point me to C source for the same information I can get it into OSHI using JNA.

Hi is this possible to get the list of NetConnection along with details -
LocalAddress 0.0.0.0
LocalPort 56084
RemoteAddress 0.0.0.0
RemotePort 0
Type UDP
State LISTEN
SendQueue 4294967295
ReceiveQueue 4294967295

Using OSHI,, in any ways ,, @dbwiddis your help is most needful

It's possible to get that information using the command line netstat command. OSHI does have a utility function to put command line output into a list of strings for processing. Otherwise, OSHI does not try to store or report this information in any way.

Thank you @dbwiddis, is there any test/examples to work around oshi utility function to use netstat command?

        // add switches to netstat command for data you want
        List<String> netstat = ExecutingCommand.runNative("netstat"); 
        for (String line : lines) {
            // trim off left whitespace
            String leftTrimmed = line.replaceFirst("^\\s+", "");
            // split columns by whitespace
            String[] split = ParseUtil.whitespaces.split(leftTrimmed);
            // make sure we have enough columns
            if (split.length < 2) { 
                return "";
            }
            // pull out the column you want and process it
            return split[1].split(":")[0];
        }

Thank you @dbwiddis, , :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jflefebvre06 picture jflefebvre06  路  9Comments

antonio-rodriges picture antonio-rodriges  路  12Comments

Shikari0744 picture Shikari0744  路  7Comments

andrea9293 picture andrea9293  路  8Comments

UnAfraid picture UnAfraid  路  5Comments