PDA

View Full Version : How to change IP address via cocoa program/ other program




KenLin
Jul 4, 2007, 01:25 AM
Dear All,
I want to change IP address via cocoa's API or other function.
Is anyone knows how to change IP in program?

Thanks!
Ken Lin in trouble :apple:



janey
Jul 4, 2007, 01:26 AM
and why would you need to change an IP address?

KenLin
Jul 4, 2007, 01:42 AM
Dear janey:
I want to write a program to change IP easier via cocoa.

Thanks,
Ken

janey
Jul 4, 2007, 01:45 AM
Dear Ken,

My question is asking you why one would want to change an IP address in such a manner when there are so many things that factor into this that the end user does not have control over?

Thanks,
Jane

KenLin
Jul 4, 2007, 02:19 AM
Dear Ken,

My question is asking you why one would want to change an IP address in such a manner when there are so many things that factor into this that the end user does not have control over?

Thanks,
Jane
_______
Dear Jane:
Because i want to write a wireless dongle program, and i need to change / specify dongle's host IP address.

Thanks
Ken

blaster_boy
Jul 4, 2007, 10:42 AM
You could always do a shell out from your program to launch ifconfig with the required settings to change the ip address.

lancestraz
Jul 4, 2007, 08:30 PM
You can do this in Terminal.
sudo ifconfig en1 inet 192.168.0.1
And I imagine you can run a shell script via cocoa.

KenLin
Jul 5, 2007, 12:44 AM
Thanks: Jane, blaster_boy & lancestraz:

Yes, shell script can work.
Do u have any other method to change IP address? like API or other functions?

Ken

Eraserhead
Jul 5, 2007, 03:35 AM
And I imagine you can run a shell script via cocoa.

Btw how do you do that?

robbieduncan
Jul 5, 2007, 03:58 AM
Btw how do you do that?

NSTask (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/Reference/Reference.html)

Eraserhead
Jul 5, 2007, 05:04 AM
NSTask (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/Reference/Reference.html)

Thanks :), not knowing this has led me to go via Applescript to do it :o, though it is a one-off usage so it's not a big deal.