开发者

How to measure bandwith of an SSH tunnel?

开发者 https://www.devze.com 2023-02-20 06:41 出处:网络
I\'m running a SSH Tunnel with OpenSSH on linux using the subprocess python modu开发者_开发问答le.

I'm running a SSH Tunnel with OpenSSH on linux using the subprocess python modu开发者_开发问答le. I want to find out how many bytes were sent and received from that SSH tunnel.

How can I find it out?


ssh(1) provides no mechanism for this. The OS does not provide a mechanism for this. Packet sniffing with e.g. tcpdump(1) is an option, but that would probably require root privileges, and would only be approximate if ssh(1) connections are made to the remote peer outside of your application. IPTables Accounting would give you similar tradeoffs, but would probably be much less overhead than tcpdump(1).

If you don't mind being very approximate, you could keep track of all the data you send to and read from your subprocess. ssh(1) will compress data before encrypting it, so you might over-estimate the amount of data sent, but ssh(1) will also have some overhead for re-keying, channel control, message authenticity, and so on, so it might even come close for 'average' data.

Of course, if a router along the way decides to drop every other packet, your TCP stack will send twice the data, maybe more.

Very approximate indeed.


You could measure the raw ssh transfer with something like pv:

ssh user@remote -t "cat /dev/urandom" | pv > /dev/null ssh user@remote -t "pv > /dev/null" < /dev/urandom

(you could try with /dev/zero - but if you are using ssh compression, you'd get a very unreal transfer rate.)

0

精彩评论

暂无评论...
验证码 换一张
取 消