Exemplo n.º 1
0
    def set_network_config(self, interface='eth0'):
        pinfo("Setting up network configuration")
    
        while True:
            self.ip = input("[ * ] Enter IPv4 addess (x.x.x.x) or \"dhcp\" :\n")
            if self.ip == "dhcp":
                break
            if ipv4(self.ip):
                while True:
                    self.netmask = input("[ * ] Enter netmask (255.255.255.0) :\n")
                    if ipv4(self.netmask):
                        break
                while True:
                    self.gateway = input("[ * ] Enter the default gateway or \"none\" :\n")
                    if self.gateway == "none":
                        self.gateway = None
                        break
                    if ipv4(self.gateway):
                        break
                break
    
        f = open(self.new_root + '/etc/network/interfaces', "w")
        if self.ip == "dhcp":
             f.write("""auto lo
iface lo inet loopback

auto %s
iface %s inet dhcp""" % (interface, interface))
        else:
            netconf = """auto lo
iface lo inet loopback

auto %s
iface %s inet static
  address %s
  netmask %s""" % (interface, interface, self.ip, self.netmask)
            if not self.gateway == None:
                f.write(netconf + "\n  gateway %s" % self.gateway)
            else:
                f.write(netconf)

        f.close()
Exemplo n.º 2
0
    def set_network_config(self, interface='eth0'):
        pinfo("Setting up network configuration")
    
        while True:
            self.ip = input("[ * ] Enter IPv4 addess (x.x.x.x) or \"dhcp\" :\n")
            if self.ip == "dhcp":
                break
            if ipv4(self.ip):
                while True:
                    self.netmask = input("[ * ] Enter netmask (255.255.255.0) :\n")
                    if ipv4(self.netmask):
                        break
                while True:
                    self.gateway = input("[ * ] Enter the default gateway or \"none\" :\n")
                    if self.gateway == "none":
                        self.gateway = None
                        break
                    if ipv4(self.gateway):
                        break
                break
    
        f = open(self.new_root + '/etc/sysconfig/network-scripts/ifcfg-' + interface, "w")
        if self.ip == "dhcp":
             f.write("""DEVICE=%s
BOOTPROTO=dhcp
NM_CONTROLLED=\"no\"
ONBOOT=\"yes\"\n""" % interface)
        else:
            netconf = """DEVICE=%s
BOOTPROTO=static
NM_CONTROLLED=\"no\"
ONBOOT=\"yes\"
IPADDR=%s
NETMASK=%s\n""" % (interface, self.ip, self.netmask)
            if not self.gateway == None:
                f.write(netconf + "GATEWAY=%s\n" % self.gateway)
            else:
                f.write(netconf)

        f.close()