Example #1
0
def del_route(subnet, netmask=None):
    # netmask is not needed in Win32, but added that to ensure
    # interface compatibility w/ linux2 target where mask is needed
    # to manipulate a static route table entry.
    chk_ip_sanity(subnet)
    chk_ip_sanity(netmask)
    subp = Popen(ROUTE_DEL_CMDLINE % {'subnet': ip2str(subnet), },
            stdout=PIPE, stderr=PIPE)
    out, err = subp.communicate()
    return parse_route_cmd(out, err, subp.returncode)
Example #2
0
def del_route(subnet, netmask): # netmask a must in linux2 targets
    chk_ip_sanity(subnet)
    chk_ip_sanity(netmask)
    subp = Popen(args=(ROUTE_DEL_CMDLINE % {
            'subnet': ip2str(subnet),
            'mask': ip2str(netmask),
            }).split(' '),
            stdout=PIPE, stderr=PIPE)
    out, err = subp.communicate()
    return parse_route_cmd(out, err, subp.returncode)
Example #3
0
def add_route(subnet, netmask, gateway, permanent=False):
    chk_ip_sanity(subnet)
    chk_ip_sanity(gateway)
    chk_ip_sanity(netmask)
    if permanent is True:
        perm = '-p'
    else:
        perm = ''
    # validation made later to "fix" TOCTTOU
    # (although by no means completely avoiding)
    subp = Popen(ROUTE_ADD_CMDLINE %
            {'perm': perm,
             'subnet': ip2str(subnet),
             'mask': ip2str(netmask),
             'gateway': ip2str(gateway),
             }, stdout=PIPE, stderr=PIPE)
    out, err = subp.communicate()
    return parse_route_cmd(out, err, subp.returncode)