LinuxQuestions.org

LinuxQuestions.org (http://www.linuxquestions.org/questions/index.php)
-   Linux - Networking (http://www.linuxquestions.org/questions/forumdisplay.php?f=3)
-   -   Get Currently connected Network Name? (http://www.linuxquestions.org/questions/showthread.php?t=519354)

samvel 01-14-2007 11:28 PM

Get Currently connected Network Name?
 
Configuration:
Laptop with KUbuntu 6.10 running on it.

Problem:
I have a laptop with SSHD running on it. The situation is that SSHD server is only used at home and should be turned off whenever I am connected to network at work/office (security restrictions out there). So, I need somehow to let my laptop start SSHD server only whenever I am at home and connected to home network of course administrated by myself.

Solution:
One possible solution of given problem is to put simple BASH script in /etc/init.d/start_ssh.sh that would start SSHD server or not depending on currently connected NETWORK name. The only problem here is how to get that NETWORK name in BASH (Python/C++/(T)CSH)? Any Ideas?



P.S. I have found some interesting folders in /etc/network/ with names:
if-down.d
if-post-down.d
if-pre-up.d
if-up.d
Maybe as a solution start_ssh.sh script should be put there which will be executed each time network is changed? What is their purpose?

tredegar 01-15-2007 03:57 AM

Do you get a different address when you are at work?
ifconfig eth0 | grep inet will tell you your network address.
Then you could write some bash / sed / awk / python / whatever to decide whether to start sshd or not.

samvel 01-15-2007 08:18 AM

Quote:

Originally Posted by tredegar
Do you get a different address when you are at work?
ifconfig eth0 | grep inet will tell you your network address.
Then you could write some bash / sed / awk / python / whatever to decide whether to start sshd or not.

Yes, I do get different IP address.

archtoad6 01-15-2007 02:24 PM

It might be as easy as:
Code:

[ ifconfig eth0 | grep 'inet: addr:192' ] && sshd
or something similar. Where "192" is the shortest string that uniquely distinguishes your home LAN from work.

samvel 01-17-2007 11:00 AM

iwconfig
 
The solution is simple as usual. iwconfig will give me Access Point which is unique and can be used in order to get idea where am I working at: Home or Office.

The only problem is how to get the same information for wired connections? Sometimes I am using my cable network card. Any ideas?


All times are GMT -5. The time now is 12:29 AM.