 |
 |
detecting IP address change
|
 |
|
 |
|
Junior Member
Join Date: Apr 2005
Status:
Offline
|
|
Is there any script that is called when an OS X machine gets connected to a network or switches from one network to another (i.e. when the IP address or interface change). I am trying to find an automatic way to restart ipfw, so that it uses the correct IP address and interface. I found something similar:
here under Dynamic IP address with ppp ..., but it is not for en0 or en1.
Any ideas how to do this for en0 and en1?
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
I don't know how to do this with the OS X GUI, but you could create a simple shell script to do this simply by extracting the rule sets for both firewall configs via a:
sudo ipfw list
creating a shell script like the following:
Code:
#/bin/sh
ipfw flush
[your rules]
Set the script with executable permissions, and you can give it a .command extension so that it is double-clickable if you want.
The ipfw flush command will clear the firewall's currently loaded rule set, so essentially this script will allow you to unload your old rule set, and load in the new rule set. You'll need root/sudo access to run it.
Does this make sense?
|
|
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
And if you want to get the IP addresses for all available interfaces, you can do it like this:
Code:
INTERFACES=(`/sbin/ifconfig -l -u`)
for INTERFACE in ${INTERFACES[@]}
do
     IP=`/sbin/ifconfig $INTERFACE | /usr/bin/grep 'inet ' | /usr/bin/cut -f 2 -d ' '` # get the IP address
     # do whatever you want with the IP
done
If you just want to check a particular interface, like Ethernet or AirPort, you can replace $INTERFACE in there with en0, en1, or whatever you like.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2005
Status:
Offline
|
|
Thanks for the responses, but this is not what I am looking for. The problem is not how to restart ipfw or how to get the IP addresses for the different interfaces, but when to do it.
In the link in my original post, it says that there is a script that runs automatically when the machine gets connected via ppp. Basically I am looking for the same thing, but for en0 and en1.
For example the following situation: I have my laptop connected to a network via en0 and it has a DHCP assigned IP address. Then I disconnect the laptop, move it to another location and connect it to a wireless network and it gets another DHCP assigned IP address. I need something that automatically detects that the laptop got connected to a new network (IP address or the interface changed).
I can run a script (similar to the one that besson3c suggested) manually, whenever I disconnect the laptop and connect it to a new location, but it would be better to be done automatically. I also thought of writing a script that checks the IP address every minute or so and if it changes, restart the firewall, but that doesn't sound like a good idea.
The best thing would be to find if there is something that runs automatically on network connect (similar to the ppp case) or something that sends notification of network change.
|
|
|
| |
|
|
|
 |
|
 |
|
Administrator 
Join Date: Apr 2001
Location: San Antonio TX USA
Status:
Offline
|
|
Are you looking for somethign that will allow you to use your very mobile laptop as a server for something? I don't think any of the DNS update services will help here, so boy, do you need something else! If that's not your aim, what is it you ARE trying to do?
|
|
Glenn -----
OTR/L, MOT, Tx
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2005
Status:
Offline
|
|
Originally Posted by ghporter
Are you looking for somethign that will allow you to use your very mobile laptop as a server for something? I don't think any of the DNS update services will help here, so boy, do you need something else! If that's not your aim, what is it you ARE trying to do?
No, I am not trying to use the laptop as a server. What I am trying to do is to modify the instructions in the link in my original post so that they work with dynamic IP address via en0 or en1. I guess I will email the instructions author and ask him.
Edit: The instructions in that link use the actual IP address of my machine ($oip in that script) ratner than 'me' that is used in most ipfw scripts that I've seen. This requires that ipfw be restarted whenever the IP address changes. In the case of ppp connection there is a convinient place where one can place a script (e.g. to restart the firewall) whenever the machine gets connected via ppp. However, the author doesn't mention anything about dynamic IP address and en0 or en1.
Not sure if this is clear, but I don't want to copy the whole page linked in my original post.
(Last edited by aux; Sep 23, 2006 at 11:25 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2005
Status:
Offline
|
|
Update: after some thought I decided to use combination of 'me' and 'any' instead. Not sure if it is as good as using the exact IP address, but hopefully will work.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|