replacement of netstat

1,293 views
Skip to first unread message

Jan-Erik Rediger

unread,
Mar 12, 2012, 9:09:17 AM3/12/12
to sshuttle
Hey,

netstat included in the net-tools is more or less obsolete on modern
Linux systems[1] and therefore deprecated in some distributions
already[2].
On linux systems the calls to netstat (for routes and sockets) can be
easily replaced by "ip route" and "ss". (See patch [3] or at the end
of this post)

I now know that "ip" and "ss are Linux-only non-portable programs I
think sshuttle should atleast have an option to change the internally
used program (similar to the "--python" switch).

Jan-Erik

[1]: http://www.linuxfoundation.org/collaborate/workgroups/networking/net-tools
[2]: http://www.archlinux.org/news/deprecation-of-net-tools/
[3]: https://github.com/apenwarr/sshuttle/pull/14


From 8711ae6caf58dea91540942e56b8a3d2d4813441 Mon Sep 17 00:00:00 2001
From: Jan-Erik Rediger <bad...@archlinux.us>
Date: Sat, 10 Mar 2012 20:09:18 +0100
Subject: [PATCH] replace netstat with "ip route" and "ss"

---
hostwatch.py | 2 +-
server.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hostwatch.py b/hostwatch.py
index 66e7461..5f57600 100644
--- a/hostwatch.py
+++ b/hostwatch.py
@@ -111,7 +111,7 @@ def _check_dns(hostname):

def _check_netstat():
debug2(' > netstat\n')
- argv = ['netstat', '-n']
+ argv = ['ss']
try:
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE,
stderr=null)
content = p.stdout.read()
diff --git a/server.py b/server.py
index e1b327d..122cdd0 100644
--- a/server.py
+++ b/server.py
@@ -47,7 +47,7 @@ def _shl(n, bits):


def _list_routes():
- argv = ['netstat', '-rn']
+ argv = ['ip', 'route']
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE)
routes = []
for line in p.stdout:
--
1.7.9.3

Avery Pennarun

unread,
Mar 12, 2012, 3:40:30 PM3/12/12
to Jan-Erik Rediger, sshuttle
From [2], "net-tools will continue to be in the repositories, so
scripts relying on it should still work." Nobody is likely to drop
the netstat command for an *extremely* long time. It has a lot of
functionality beyond just looking at routes, and it's relatively
standardized.

In particular, I could add code to use ip/ss instead of netstat, but
a) nobody would notice any improvement, and b) I'd still have to
maintain the netstat code for every platform *except* Linux, and c)
that would make the code bigger, harder to maintain, and harder to
test. So no benefit, high cost.

Call me back in 10 years when they actually think about dropping
netstat entirely :)

Have fun,

Avery

Reply all
Reply to author
Forward
0 new messages