/* 
IPchanger.cpp
an easy tool to change IP adresses of devices under Unix.
(c) 2003 by Takt
www.excluded.org
Takt@excluded.org
icq #141665405
*/

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
char device[15];
char newIP[15];
char subnet[15];
char down[1024];
char up[1024];

cout << "Warning! You MUST be ROOT\n";
cout << "Wich devices Ip do you want to change?\n";
cin >> device;
cout << "Changeing IP of " << device << endl;
cout << "Wich IP should be set?\n";
cin >> newIP;
cout << "Wich Subnetmask? default is 255.255.255.0\n";
cin >> subnet;
cout << "Changeing IP, please wait...\n";
snprintf(down, sizeof(down), "%s %s %s", "ifconfig", device, "down");
cout << down << endl;
system(down);

cout << device << " is off!\n";
cout << "Starting  " << device << " again!\n";

snprintf(up, sizeof(up), "%s %s %s %s %s %s", "ifconfig", device, newIP, "netmask", subnet, "up");
cout << up << endl;
system(up);
cout << "IP has been changed\n";


return 0;
}