LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2008, 03:55 PM   #1
aarontwc
Member
 
Registered: Oct 2008
Posts: 66

Rep: Reputation: 15
Check if there is traffic within SSH


In Perl/C implementing an SSH connection (using port forwarding). How do one actually check what is going on inside the SSH tunnel? For example: ssh -L 5902:localhost:10003 <remotehost>

I want to basically check whether there is traffic between this connection.

thanks
Aaron
 
Old 11-15-2008, 01:20 AM   #2
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 270

Rep: Reputation: 33
Quote:
Originally Posted by aarontwc View Post
I want to basically check whether there is traffic between this connection.
the following procedure may be helpful to you....

Quote:
step - 1: execute your C/perl code which initiates the ssh connection.

step - 2: check the list of tcp connections with the help of "netstat --tcp". Identify the ssh connection and see the client port number of it.

step - 3: start the wireshark and capture the packets with applying the filter expression "tcp.srcport == <client port>"
 
Old 11-17-2008, 10:07 PM   #3
aarontwc
Member
 
Registered: Oct 2008
Posts: 66

Original Poster
Rep: Reputation: 15
Hi there,

I am basically trying to check if there is a vncviewer connecting to a vncserver through SSH.

I was playing around with netstat for a bit and found a very interesting behaviour when vncviewer is connecting to a vncserver through an SSH tunnel.

Basically i setup port forwarding: SSH -L 10001:localhost:5900 <remote-host>
Then. with the command: netstat -t | grep <remote-host>, i realise:

1.) When RECV-Q is = 0, it means there is no user activity -> When RECV-Q == 0 it means that there is no activity within SSH
2.) When RECV-Q is > 0, it means there is user activity
3.) When SEND-Q is = 0 or > 1504, it means SSH connection is active and host is alive.
4.) When SEND-Q is = 1504, it means SSH connection is active, but host is dead.

Do you think this result will hold? I am just doing this through general testing of behaviour, do you think this approach would be better than using wireshark? I am trying to refrain from using external packages and instead rely on built in tools.

Thanks
aaron
http://aarontwc.blogspot.com
 
Old 11-18-2008, 01:54 AM   #4
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 270

Rep: Reputation: 33
what is the concept of 1504 here? I didn't get......!!!
 
Old 11-18-2008, 01:55 AM   #5
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 270

Rep: Reputation: 33
Quote:
Originally Posted by aarontwc View Post
I am trying to refrain from using external packages and instead rely on built in tools.
use tcpdump.
 
Old 11-18-2008, 03:09 AM   #6
aarontwc
Member
 
Registered: Oct 2008
Posts: 66

Original Poster
Rep: Reputation: 15
Hi,

1504 is basically a fixed amount of byte that netstat sends to 'test'.

Anyhow, I am indeed playing with tcpdump right this moment. but it is not really returning me anything.

I tried tcpdump -i eth0 tcp port 5902

Also.. actually i was thinking.. maybe the best way to do it is really to check tcp traffic of the program than the port.

Is there any program that I can use to track tcp traffic of a process ID?

THANKS!!!!
Aaron
 
Old 11-26-2008, 03:56 AM   #7
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 270

Rep: Reputation: 33
Quote:
Originally Posted by aarontwc View Post
Is there any program that I can use to track tcp traffic of a process ID?
use the netstat with -p option. you will get the process id too.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Routing SSH traffic jbarnes1967 Linux - Networking 4 06-30-2008 09:38 PM
Redirect All Traffic Through SSH wwnexc Linux - Networking 2 03-14-2007 05:37 AM
telnet /ssh traffic trican Linux - Networking 2 01-29-2007 08:16 AM
Look at all this ssh traffic! stakhous Linux - Networking 6 09-26-2005 12:23 AM
How To Check Traffic Usage/Bandwidth pjbeal Linux - Newbie 4 12-14-2004 06:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration