ubuntu - Configure file /etc/network/interface with java -
i need configure network interface on ubuntu. code
/* * change template, choose tools | templates * , open template in editor. */ package epsetupserv.network; import epsetupapi.entity.networkentity; import epsetupserv.config.generalconfigurator; import epsetupserv.lib.fileoperation; import epsetupserv.lib.shellaccess; import java.util.arraylist; import java.util.list; /** * * @author nununeh */ public class networkconfigurator { private static string realpath = "/etc/network/"; private static string realfile = "interface"; public static list<networkentity> getrealnetworkinterface() { list<networkentity> list = new arraylist<networkentity>(); int eth0_loc = fileoperation.findstringline(realpath, realfile, "auto eth0"); int eth1_loc = fileoperation.findstringline(realpath, realfile, "auto eth1"); int tline = fileoperation.countline(realpath, realpath); generalconfigurator gn = new generalconfigurator(realpath, realfile); gn.setdelimiter(" "); networkentity n1 = new networkentity(); n1.setaddress(gn.getproperty("address", eth0_loc, eth1_loc)); n1.setnetmask(gn.getproperty("netmask", eth0_loc, eth1_loc)); n1.setnetwork(gn.getproperty("network", eth0_loc, eth1_loc)); n1.setbroadcast(gn.getproperty("broadcast", eth0_loc, eth1_loc)); list.add(n1); networkentity n2 = new networkentity(); n2.setaddress(gn.getproperty("address", eth1_loc, tline)); n2.setnetmask(gn.getproperty("netmask", eth1_loc, tline)); n2.setnetwork(gn.getproperty("network", eth1_loc, tline)); n2.setbroadcast(gn.getproperty("broadcast", eth1_loc, tline)); list.add(n2); return list; } public static void setrealnetworkinterface(networkentity n1, networkentity n2) { int tline = fileoperation.countline(realpath, realfile); fileoperation.clearbyline(realpath, realfile, 1, tline); fileoperation.insertnewline(realpath, realfile, "" + "# generated epanel\\nn" + "auto lo\n" + "iface lo inet loopback\n" + "\n" + "auto eth0\n" + "iface eth0 inet static\n" + " address " + n1.getaddress() + "\n" + " netmask " + n1.getnetmask() + "\n" + " network " + n1.getnetwork() + "\n" + " broadcast " + n1.getbroadcast() + "\n" + "\n" + "auto eth1\n" + "iface eth1 inet static\n" + " address " + n2.getaddress() + "\n" + " netmask " + n2.getnetmask() + "\n" + " network " + n2.getnetwork() + "\n" + " broadcast " + n2.getbroadcast() + "\n"); } } the problem when use class, cannot change 1 one property. if want change address eth1, have change of them 1 proccess run (all property below eth0 , eth1). have alternative code?
Comments
Post a Comment