예제 #1
0
파일: main.py 프로젝트: pengxiaojun/ipsan
def loop():
    # start a thread to watch upgrade file
    os.system('clear')  # clear screen
    colorinfo.show_info("Welcome to use ubique ipsan. Press 'h' to view help")
    while True:
        try:
            r = input(prompt)
            process_input(r)
        except KeyboardInterrupt:
            print()
            pass
        except EOFError:
            print()
            pass
예제 #2
0
파일: main.py 프로젝트: BillTheBest/ipsan
def loop():
    # start a thread to watch upgrade file
    os.system('clear')  # clear screen
    colorinfo.show_info("Welcome to use ubique ipsan. Press 'h' to view help")
    while True:
        try:
            r = input(prompt)
            process_input(r)
        except KeyboardInterrupt:
            print()
            pass
        except EOFError:
            print()
            pass
예제 #3
0
파일: main.py 프로젝트: pengxiaojun/ipsan
def ifcfg():
    interfaces = get_nic_interfaces()
    interfaces = [inter for inter in interfaces if inter['interface'] != 'lo']
    nic = len(interfaces) - 1
    address = None
    gateway = None
    mask = '255.255.255.0'

    for i, name in enumerate(interfaces):
        colorinfo.show_info("%s: %s" % (i, name))

    r = input(colorinfo.format_input_text('Choice a interface[0..%s]? ' % nic))
    if not r.isnumeric():
        colorinfo.show_fail('Input must be a number.')
        return
    n = int(r)
    if n < 0 or n > nic:
        colorinfo.show_fail('Input must in range [0..%s].' % nic)
        return
    interface = interfaces[n]['interface']
    r = input(colorinfo.format_input_text('%s IP ? ' % interface))
    address = validate_ip(r)
    if address is None:
        colorinfo.show_fail('Invalid ip')
        return
    r = input(colorinfo.format_input_text('%s Mask ? ' % interface))
    if len(r) > 0:
        r = validate_ip(r)
        if r:
            mask = r
    r = input(colorinfo.format_input_text('%s Gateway ? ' % interface))
    if len(r) == 0:
        colorinfo.show_warning('Skip config gateway')
    else:
        r = validate_ip(r)
        if r:
            gateway = r

    colorinfo.show_info('-'*30)
    colorinfo.show_info('Interface=%s' % interface)
    colorinfo.show_info('IP=%s' % address)
    colorinfo.show_info('MASK=%s' % mask)
    if gateway:
        colorinfo.show_info('GATEWAY=%s' % gateway)
    colorinfo.show_info('-'*30)

    r = confirm('Save network configuration')

    if r:
        config_ip(interface, address, mask, gateway)
예제 #4
0
파일: main.py 프로젝트: pengxiaojun/ipsan
def show_ip():
    r = ifconfig()
    if r:
        colorinfo.show_info(r)
예제 #5
0
파일: main.py 프로젝트: pengxiaojun/ipsan
def help():
    colorinfo.show_info('help      # show this message')
    colorinfo.show_info('stat      # view ipsan status')
    colorinfo.show_info('if        # show ip address')
    colorinfo.show_info('ifcfg     # config ip address')
    colorinfo.show_info('reboot    # reboot ipsan')
    colorinfo.show_info('poweroff  # poweroff ipsan')
예제 #6
0
파일: main.py 프로젝트: BillTheBest/ipsan
def ifcfg():
    interfaces = get_nic_interfaces()
    interfaces = [inter for inter in interfaces if inter['interface'] != 'lo']
    nic = len(interfaces) - 1
    address = None
    gateway = None
    mask = '255.255.255.0'

    for i, name in enumerate(interfaces):
        colorinfo.show_info("%s: %s" % (i, name))

    r = input(colorinfo.format_input_text('Choice a interface[0..%s]? ' % nic))
    if not r.isnumeric():
        colorinfo.show_fail('Input must be a number.')
        return
    n = int(r)
    if n < 0 or n > nic:
        colorinfo.show_fail('Input must in range [0..%s].' % nic)
        return
    interface = interfaces[n]['interface']
    r = input(colorinfo.format_input_text('%s IP ? ' % interface))
    address = validate_ip(r)
    if address is None:
        colorinfo.show_fail('Invalid ip')
        return
    r = input(colorinfo.format_input_text('%s Mask ? ' % interface))
    if len(r) > 0:
        r = validate_ip(r)
        if r:
            mask = r
    r = input(colorinfo.format_input_text('%s Gateway ? ' % interface))
    if len(r) == 0:
        colorinfo.show_warning('Skip config gateway')
    else:
        r = validate_ip(r)
        if r:
            gateway = r

    colorinfo.show_info('-' * 30)
    colorinfo.show_info('Interface=%s' % interface)
    colorinfo.show_info('IP=%s' % address)
    colorinfo.show_info('MASK=%s' % mask)
    if gateway:
        colorinfo.show_info('GATEWAY=%s' % gateway)
    colorinfo.show_info('-' * 30)

    r = confirm('Save network configuration')

    if r:
        config_ip(interface, address, mask, gateway)
예제 #7
0
파일: main.py 프로젝트: BillTheBest/ipsan
def show_ip():
    r = ifconfig()
    if r:
        colorinfo.show_info(r)
예제 #8
0
파일: main.py 프로젝트: BillTheBest/ipsan
def help():
    colorinfo.show_info('help      # show this message')
    colorinfo.show_info('stat      # view ipsan status')
    colorinfo.show_info('if        # show ip address')
    colorinfo.show_info('ifcfg     # config ip address')
    colorinfo.show_info('reboot    # reboot ipsan')
    colorinfo.show_info('poweroff  # poweroff ipsan')