Networking Forums

Networking Forums > Computer Networking > Linux Networking > script for checking own ip address

Reply
Thread Tools Display Modes

script for checking own ip address

 
 
Marcio Cordero
Guest
Posts: n/a

 
      11-03-2005, 09:17 PM
Hi all,
I am building a script for unison. I need to check if I'm on my local
network or at school/work.
If I am at school/work, unison should synchronize with xxxx.dyndns.org, if
I'm at home it should synchronize with the same server in the local
network, e.g. 192.168.0.1. How can I find out what ip address I have? I
tried "ifconfig |grep -A 1 eth1 | grep inet" but it gives back a whole
line. How can i just get the ip address? Thanks in advance for any answer.
Regards,
Marcio
 
Reply With Quote
 
 
 
 
Jan Mannoury
Guest
Posts: n/a

 
      11-03-2005, 09:30 PM
On Thu, 03 Nov 2005 23:17:09 +0100, Marcio Cordero
<(E-Mail Removed)> wrote:

>ifconfig |grep -A 1 eth1 | grep inet


very dirty (my scripts are full of these lousy solutions but they
work):
ifconfig |grep -A 1 eth1 | grep inet |column -t -s: |awk {'print $3'}

janm
 
Reply With Quote
 
Marcio Cordero
Guest
Posts: n/a

 
      11-03-2005, 09:55 PM
Am Thu, 03 Nov 2005 23:30:13 +0100 schrieb Jan Mannoury:

> On Thu, 03 Nov 2005 23:17:09 +0100, Marcio Cordero
> <(E-Mail Removed)> wrote:
>
>>ifconfig |grep -A 1 eth1 | grep inet

>
> very dirty (my scripts are full of these lousy solutions but they
> work):
> ifconfig |grep -A 1 eth1 | grep inet |column -t -s: |awk {'print $3'}

Works prefectly. Thanks janm!
>
> janm


 
Reply With Quote
 
Marcio Cordero
Guest
Posts: n/a

 
      11-03-2005, 11:25 PM
Am Thu, 03 Nov 2005 23:30:13 +0100 schrieb Jan Mannoury:

> On Thu, 03 Nov 2005 23:17:09 +0100, Marcio Cordero
> <(E-Mail Removed)> wrote:
>
>>ifconfig |grep -A 1 eth1 | grep inet

>
> very dirty (my scripts are full of these lousy solutions but they
> work):
> ifconfig |grep -A 1 eth1 | grep inet |column -t -s: |awk {'print $3'}

Ok, that works. Now how can I check if the ip address fits in a address
range?
I'm using the following:
x=`ifconfig |grep -A 1 eth1 | grep inet |column -t -s: |awk {'print $3'}`

And then:
if [ "$x" = "192.168.0.*" ]; do
....
but I'm not sure this works. How can I find out if it's working or does
anyone have a better solution for that test?
TIA and regards,
Marcio

>
> janm


 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      11-03-2005, 11:37 PM
On Fri, 04 Nov 2005 01:25:05 +0100, Marcio Cordero wrote:
> I'm using the following:
> x=`ifconfig |grep -A 1 eth1 | grep inet |column -t -s: |awk {'print $3'}`
>
> And then:
> if [ "$x" = "192.168.0.*" ]; do
> ...
> but I'm not sure this works.


Guessing NOT.

> How can I find out if it's working


put it in a file, chmod +x filename_here

Add a line after if like
echo "It worked"
save and exit, then do a

../filename_here

to debug, you can add a
set -xv
as frist/second line of script.

set -
as last line of script you want to watch.

For extra points, read
! bash script introduction documentation
http://tldp.org/LDP/intro-linux/html/index.html
! bash script advanced documentation
http://tldp.org/LDP/abs/html/index.html
 
Reply With Quote
 
Marcio Cordero
Guest
Posts: n/a

 
      11-04-2005, 12:19 AM
Am Thu, 03 Nov 2005 18:37:26 -0600 schrieb Bit Twister:

> On Fri, 04 Nov 2005 01:25:05 +0100, Marcio Cordero wrote:
>> I'm using the following:
>> x=`ifconfig |grep -A 1 eth1 | grep inet |column -t -s: |awk {'print $3'}`
>>
>> And then:
>> if [ "$x" = "192.168.0.*" ]; do
>> ...
>> but I'm not sure this works.

>
> Guessing NOT.
>
>> How can I find out if it's working

>
> put it in a file, chmod +x filename_here
>
> Add a line after if like
> echo "It worked"
> save and exit, then do a
>
> ./filename_here
>
> to debug, you can add a
> set -xv
> as frist/second line of script.
>
> set -
> as last line of script you want to watch.
>
> For extra points, read
> ! bash script introduction documentation
> http://tldp.org/LDP/intro-linux/html/index.html
> ! bash script advanced documentation
> http://tldp.org/LDP/abs/html/index.html


Test contructs was what I was looking for... thanks Bit Twister, it works
now!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script to change the static IP address Ezakial Windows Networking 2 09-14-2009 06:25 PM
netsh script to hard-code IP address Spin Windows Networking 2 05-11-2008 12:11 PM
Copy files using filenames from text files with shell script or bash script altariamx2003@gmail.com Linux Networking 4 11-23-2006 08:27 AM
script for changing gateway ip address J Windows Networking 3 03-13-2006 02:40 PM
checking if a MAC address exist in a LAN and which is the attached IP address john Linux Networking 8 10-24-2004 11:56 PM



1 2 3 4 5 6 7 8 9 10 11