change ip address script ...

Hi,

My goal would be to change my ip address automatically in system preferences. At work, depending from the task, we need to use different IP addresses (fixed) and I was wondering how to change ip using apple script or ui script… I just have no idea how to do that … I tried with kestroke but I get unstable results … Can anyone help me ??

thanks a lot in advance !

Hi,

hm, do you know, you can use different locations with different network settings,
which can be changed quite easy with

do shell script "scselect myNewLocation"

There’s a unix command that can change your network location (scselect) so if you have different locations set up in your network settings for each IP address then it’s simple. The following will check my current location, and if it is not my home location then it will set it to my home location.


set location_home to "home" -- the name of the location named home

set current_location to do shell script "scselect 2>&1 | grep '^ ' 2>&1 | grep '*' | cut -f 2 -d '(' | cut -f 1 -d ')'"
if current_location is not location_home then
	do shell script "scselect '" & location_home & "'"
	delay 0.5
end if

thank you for the really quick answer !

Actually, I knew that as I found a post by you in the forum :smiley: !

My problem is that to automatise tasks, I would have to create more than 100 locations and do the same for any… If there was a way to prevent this boring “creating location” time, I would really go for it ! Basically we have a fixed IP 000.00.00.0XX and I would have to execute a a task for all the 99 “XX” combinations… Any easy way for this or is it easier to just go ahead and crete the locations ?

thanks!!!

I don’t know of any other way. If you post your keystroke script, maybe we can help you make it more stable. My advice for ui scripting is to always make sure the app your scripting is the frontmost app, and to put delays in between the keystrokes.

Ok, I’ll bite.

What tasks would be requiring you to change your IP to 100 possible different addresses?

Call a shell command from applescript to change your IP address. Run a man on networksetup for details on the command. For example, I am doing the following:

do shell script "networksetup -setmanual Ethernet " & macIP & " " & macSubnet & " " & macGateway password macPWD with administrator privileges

Obviously macIP, macSubnet, macGateway, and macPWD are all variables.

Stunningly, I had to go onto a Unix admins’ board to find this command. I tried ifconfig at first, since OSX is unix under the hood, but of course apple had to change a perfectly good command that’s been working fine in the unix world since the dawn of time. :wink:

Anyways - this has been a godsend for me. I have over 200 machines going out soon and manual configuration was not an option. I had tried the GUI scripting approach, but that was unreliable as windows could lose focus or a tech could click off and screw the keystrokes up.

IMHO, GUI scripting is not ready for prime time and should never be used for enterprise level application.