Ejemplo n.º 1
0
    def create_lswitch_port(self,
                            lswitch=None,
                            lport_create_args={},
                            iteration=0,
                            ext_cidr=None):
        cidr = lswitch.get("cidr", None)
        if cidr:
            ip = str(
                next(netaddr.iter_iprange(cidr.ip + iteration + 1, cidr.last)))
            ip_mask = '{}/{}'.format(ip, cidr.prefixlen)
            gw = str(netaddr.IPAddress(cidr.last - 1))
            name = "lp_{}".format(ip)
        else:
            name = "lp_".join(
                random.choice(string.ascii_letters) for i in range(10))
            ip_mask = ""
            ip = ""
            gw = ""
        if ext_cidr:
            ext_gw = str(netaddr.IPAddress(ext_cidr.last - 2))
        else:
            ext_gw = ""

        print("***** creating lport {} *****".format(name))
        lswitch_port = self.nbctl.ls_port_add(lswitch["name"],
                                              name,
                                              mac=str(RandMac()),
                                              ip=ip_mask,
                                              gw=gw,
                                              ext_gw=ext_gw)
        return lswitch_port
Ejemplo n.º 2
0
def start():
    pass
    start_time = time.time()
    try:
        os.system('cls' if os.name == 'nt' else 'clear')
        num = int(input("\n\n\tEnter an number: "))
        os.system('cls' if os.name == 'nt' else 'clear')
        print("Number of generated keys: ", num)
        print("\n")
        for _ in range(0, num):
            example_mac = "00-00-00-00-00-00"
            generated_mac = RandMac(example_mac)            
            print("[+] Generated 6-byte mac address: ",generated_mac)
            
        end = time.time()
        print("\n\n\t[*] Total time elapsed:>  ", end - start_time)
            
    except ValueError:
        os.system('cls' if os.name == 'nt' else 'clear')
        print("\n\n\n\t[/] Input number only...")  
        print("\n\n\n\t[*] Try Agian [*]")
        time.sleep(2)
        start()
    except KeyboardInterrupt:
        print("[+] CTRL+C detected [+]")
        os.system('cls' if os.name == 'nt' else 'clear')
        sys.exit()
Ejemplo n.º 3
0
 def generate_mac_address(self, numbers_of_mac_addr):
     temp = []
     mac_addr = []
     for i in range(0, numbers_of_mac_addr):
         temp.append(RandMac("00:00:00:00:00:00", True))
     for i in temp:
         mac_addr.append(i.mac)
     return mac_addr
Ejemplo n.º 4
0
def change_mac():
    new_mac = str(RandMac("00-00-00-00-00-00")).upper()[1:-1]
    req_str = f'http://192.168.1.1/userRpm/MacCloneCfgRpm.htm?mac1={new_mac}&wan=1&Save=%D0%A1%D0%BE%D1%85%D1%80%D0%B0%D0%BD%D0%B8%D1%82%D1%8C'
    req = Request(req_str)
    req.add_header('Authorization', ('Basic %s' % base64.b64encode(
        'olexandr:routersettings'.encode('ascii')).decode('ascii')))
    req.add_header('Referer', 'http://192.168.1.1')
    urlopen(req)
Ejemplo n.º 5
0
 def connect_lswitch_to_router(self, lrouter=None, lswitch=None):
     gw = netaddr.IPAddress(lswitch["cidr"].last - 1)
     lrouter_port_ip = '{}/{}'.format(gw, lswitch["cidr"].prefixlen)
     mac = RandMac()
     lrouter_port = self.nbctl.lr_port_add(lrouter["name"], lswitch["name"],
                                           mac, lrouter_port_ip)
     lswitch_port = self.nbctl.ls_port_add(lswitch["name"],
                                           "rp-" + lswitch["name"],
                                           lswitch["name"])
Ejemplo n.º 6
0
def ipv4(prefix: str, ipl: [IPv4Address] = None, macl: [str] = None) -> [(IPv4Address, str, IPv4Address, int)]:
    """
    This function generate a list of IPs and MACs to insert.

    If a list is given, they avoid duplicated entry with list, for duplicated IP the MAC will be set to None.

    :param prefix: The IPs prefix
    :type prefix: IPv4Address
    :param ipl: A list of IPs
    :type ipl: [IPv4Address]
    :param macl: A list of MACs
    :type macl: [str]
    :return: list of tuple with IP, MAC, subnet mask and cidr
    :rtype: [(IPv4Address, str, IPv4Address, int)]
    """

    if ipl is None:
        ipl = []
    if macl is None:
        macl = []
    out = []

    # Check if prefix is valid
    try:
        ips = IPv4Network(prefix)
    except (ValueError, AddressValueError, NetmaskValueError):
        raise ValueError("Invalid prefix !")
    subnet_mask = ips.netmask
    cidr = ips.prefixlen

    # For all ip in prefix
    for ip in ips.hosts():
        mac = None
        if ip not in ipl:
            ipl.append(ip)
            mac = str(RandMac("00:00:00:00:00:00", True)).replace("'", "")
            while mac in macl:
                mac = str(RandMac("00:00:00:00:00:00", True)).replace("'", "")
            macl.append(mac)

        out.append((ip, mac, subnet_mask, cidr))
    return out
Ejemplo n.º 7
0
    def create_cluster_join_switch(self, sw_name):
        self.join_switch = self.nbctl.ls_add(sw_name,
                                             self.cluster_cfg.gw_net)

        lrp_ip = netaddr.IPAddress(self.cluster_cfg.gw_net.last - 1)
        self.join_rp = self.nbctl.lr_port_add(
            self.router, 'rtr-to-join', RandMac(), lrp_ip,
            self.cluster_cfg.gw_net.prefixlen
        )
        self.join_ls_rp = self.nbctl.ls_port_add(
            self.join_switch, 'join-to-rtr', self.join_rp
        )
Ejemplo n.º 8
0
def hotspot():
    channels = [
        3, 4, 5, 8, 7, 9, 10
    ]  #list of channel from which a channel will be used to broadcast
    random_mac = RandMac("00:00:00:00:00:00", True)
    line = "create_ap -c " + str(channels[random.randint(
        0,
        len(channels) - 1)]) + " --hidden --mac " + str(
            random_mac) + " " + wireless + " " + lan + " " + randomString(
                random.randint(1, 4)) + " " + randomString(8)
    print(line)
    os.system(line)
Ejemplo n.º 9
0
def ansible1():
    output_array = []
    database_list = {}
    req = request.json
    # req = request.values.values()
    service_name = req["User_data"]["service"]
    username = req["User_data"]["account"]
    database_list["account"] = username
    database_list["service"] = service_name
    query = {"account": username}
    notified_query = {"account": username, "service": service_name}
    json_query = json.dumps(notified_query)
    if service_name == "SSH":
        item_onet = "onetssh.yml"
        item_dnet = "dnetssh.yml"
    elif service_name == "HTTP":
        item_onet = "onethttp.yml"
        item_dnet = "dnethttp.yml"
    elif service_name == "MYSQL":
        item_onet = "onetmysql.yml"
        item_dnet = "dnetmysql.yml"
    else:
        print("Wrong service selected")
        return
    ansible_script = read_file(script_inventory + item_onet)
    edited_script = scripts_necessary_changes_VM_onet(ansible_script,
                                                      item_onet, username)
    new_script_path = write_file(script_inventory + item_onet, edited_script)
    ipaddress = execute_VM_scripts(new_script_path, item_onet)
    database_list["onet_VM_ip"] = ipaddress
    delete_file(new_script_path)
    tuntap = get_tap_interface_name(query)
    MAC = RandMac("080027000000")
    database_list["dnet_VM_mac"] = MAC.mac
    ansible_script = read_file(script_inventory + item_dnet)
    edited_script = scripts_necessary_changes_VM_dnet(ansible_script,
                                                      item_dnet, ipaddress,
                                                      tuntap, MAC.mac)
    new_script_path = write_file(script_inventory + item_dnet, edited_script)
    VM_result = execute_VM_scripts(new_script_path, item_dnet)
    delete_file(new_script_path)
    accessing_database("VMdetails", database_list)
    database_list.clear()
    output_array.append(VM_result)
    print("above notified")
    notifiedController(json_query)
    print("below notified")
    notified_query.clear()
    query.clear()
    return jsonify(output_array)
Ejemplo n.º 10
0
    def make_mac_ip_dicts():
        # For each IP address, give it a random MAC address
        # Idea during design was to represent 3 different office locations

        # get network ranges and mac ranges from config file
        atx_cidr = cfg.get('networks', 'atx_cidr')
        dfw_cidr = cfg.get('networks', 'dfw_cidr')
        hou_cidr = cfg.get('networks', 'hou_cidr')

        atx_mac_range = cfg.get('macs', 'atx_macs')
        dfw_mac_range = cfg.get('macs', 'dfw_macs')
        hou_mac_range = cfg.get('macs', 'hou_macs')

        # Create list of IP addresses for each location
        atx_net = ipaddress.ip_network(atx_cidr)
        dfw_net = ipaddress.ip_network(dfw_cidr)
        hou_net = ipaddress.ip_network(hou_cidr)

        # make a hash of IP to MAC address for each location
        # IPs are selected - for each in a list - no duplication
        # MACs are generated randomly, duplicates are possible
        atx_mac_ip = {}
        for ip in atx_net:
            atx_mac = str(RandMac(atx_mac_range))
            atx_mac_ip[ip] = atx_mac

        dfw_mac_ip = {}
        for ip in dfw_net:
            dfw_mac = str(RandMac(dfw_mac_range))
            dfw_mac_ip[ip] = dfw_mac

        hou_mac_ip = {}
        for ip in hou_net:
            hou_mac = str(RandMac(hou_mac_range))
            hou_mac_ip[ip] = hou_mac

        return (atx_mac_ip, dfw_mac_ip, hou_mac_ip)
Ejemplo n.º 11
0
    def provision_port(self, cluster, passive=False):
        name = f'lp-{self.id}-{self.next_lport_index}'
        ip = netaddr.IPAddress(self.int_net.first + self.next_lport_index + 1)
        plen = self.int_net.prefixlen
        gw = netaddr.IPAddress(self.int_net.last - 1)
        ext_gw = netaddr.IPAddress(self.ext_net.last - 2)

        log.info(f'Creating lport {name}')
        lport = cluster.nbctl.ls_port_add(self.switch, name,
                                          mac=str(RandMac()), ip=ip, plen=plen,
                                          gw=gw, ext_gw=ext_gw, metadata=self,
                                          passive=passive, security=True)
        self.lports.append(lport)
        self.next_lport_index += 1
        return lport
Ejemplo n.º 12
0
def routerBulk(request):
    print("dfgdgf")
    rw = RandomWord(max_word_size=5)
    res = []
    val = {}
    for i in range(0, 3):

        tmp = str(rw.generate())
        val["sapid"] = tmp + str(i)
        val["hostname"] = tmp
        val["loopbackid"] = ".".join(
            map(str, (random.randint(0, 255) for _ in range(4))))
        val["mac_add"] = str(RandMac())
        ser = RouterDetailsSerializer(data=val)
        print(ser)
        if ser.is_valid():
            ser.save()
            print("****")
            res.append(val["loopbackid"])

    return Response(res)
Ejemplo n.º 13
0
    def provision(self, cluster):
        self.connect(cluster.cluster_cfg)
        self.wait(cluster.sbctl, cluster.cluster_cfg.node_timeout_s)

        # Create a node switch and connect it to the cluster router.
        self.switch = cluster.nbctl.ls_add(f'lswitch-{self.container}',
                                           cidr=self.int_net)
        lrp_name = f'rtr-to-node-{self.container}'
        ls_rp_name = f'node-to-rtr-{self.container}'
        lrp_ip = netaddr.IPAddress(self.int_net.last - 1)
        self.rp = cluster.nbctl.lr_port_add(
            cluster.router, lrp_name, RandMac(), lrp_ip,
            self.int_net.prefixlen
        )
        self.ls_rp = cluster.nbctl.ls_port_add(
            self.switch, ls_rp_name, self.rp
        )

        # Make the lrp as distributed gateway router port.
        cluster.nbctl.lr_port_set_gw_chassis(self.rp, self.container)

        # Create a gw router and connect it to the cluster join switch.
        self.gw_router = cluster.nbctl.lr_add(f'gwrouter-{self.container}')
        cluster.nbctl.run(f'set Logical_Router {self.gw_router.name} '
                          f'options:chassis={self.container}')
        join_grp_name = f'gw-to-join-{self.container}'
        join_ls_grp_name = f'join-to-gw-{self.container}'
        gr_gw = netaddr.IPAddress(self.gw_net.last - 2 - self.id)
        self.gw_rp = cluster.nbctl.lr_port_add(
            self.gw_router, join_grp_name, RandMac(), gr_gw,
            self.gw_net.prefixlen
        )
        self.join_gw_rp = cluster.nbctl.ls_port_add(
            cluster.join_switch, join_ls_grp_name, self.gw_rp
        )

        # Create an external switch connecting the gateway router to the
        # physnet.
        self.ext_switch = cluster.nbctl.ls_add(f'ext-{self.container}',
                                               cidr=self.ext_net)
        ext_lrp_name = f'gw-to-ext-{self.container}'
        ext_ls_rp_name = f'ext-to-gw-{self.container}'
        lrp_ip = netaddr.IPAddress(self.ext_net.last - 1)
        self.ext_rp = cluster.nbctl.lr_port_add(
            self.gw_router, ext_lrp_name, RandMac(), lrp_ip,
            self.ext_net.prefixlen
        )
        self.ext_gw_rp = cluster.nbctl.ls_port_add(
            self.ext_switch, ext_ls_rp_name, self.ext_rp
        )

        # Configure physnet.
        self.physnet_port = cluster.nbctl.ls_port_add(
            self.ext_switch, f'provnet-{self.container}', ip="unknown"
        )
        cluster.nbctl.ls_port_set_set_type(self.physnet_port, 'localnet')
        cluster.nbctl.ls_port_set_set_options(
            self.physnet_port,
            f'network_name={cluster.brex_cfg.physical_net}'
        )

        # Route for traffic entering the cluster.
        rp_gw = netaddr.IPAddress(self.gw_net.last - 1)
        cluster.nbctl.route_add(self.gw_router, cluster.net, str(rp_gw))

        # Default route to get out of cluster via physnet.
        gr_def_gw = netaddr.IPAddress(self.ext_net.last - 2)
        cluster.nbctl.route_add(self.gw_router, gw=str(gr_def_gw))

        # Force return traffic to return on the same node.
        cluster.nbctl.run(f'set Logical_Router {self.gw_router.name} '
                          f'options:lb_force_snat_ip={gr_gw}')

        # Route for traffic that needs to exit the cluster
        # (via gw router).
        cluster.nbctl.route_add(cluster.router, str(self.int_net),
                                str(gr_gw), policy="src-ip")

        # SNAT traffic leaving the cluster.
        cluster.nbctl.nat_add(self.gw_router, external_ip=str(gr_gw),
                              logical_ip=cluster.net)
Ejemplo n.º 14
0
    parser.add_argument("-i", "--input-file", required=True, type=str, help="The Classbench trace input file")
    parser.add_argument("-o", "--output-file", type=str, help="The output pcap file ")
    parser.add_argument("-s", "--src-mac", type=str, help="Source MAC address to use in the generated pcap")
    parser.add_argument("-d", "--dst-mac", type=str, help="Destination MAC address to use in the generated pcap")
    parser.add_argument("-l", "--pkt-size", type=int, default=0, help="Size of the generated packet")

    args = parser.parse_args()

    input_file_path = args.input_file
    if args.output_file is None:
        output_file_path = input_file_path + ".pcap"
    else:
        output_file_path = args.output_file

    if args.src_mac is None:
        srcMAC = str(RandMac("00:00:00:00:00:00", True).mac)
    else:
        srcMAC = args.src_mac

    if args.dst_mac is None:
        dstMAC = str(RandMac("00:00:00:00:00:00", True).mac)
    else:
        dstMAC = args.dst_mac

    packetSize = args.pkt_size

    try:
        os.remove(output_file_path)
    except OSError:
        pass
Ejemplo n.º 15
0
import winreg
import time
import netifaces
from randmac import RandMac
import subprocess

# preset some variables
error = False
mac = str(RandMac("000000000000", True)).replace("'", "").upper()
ifaces = netifaces.interfaces()
keypath = r"SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}"
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, keypath, 0, winreg.KEY_READ)
i = 0
adapters = []

print("---------------------------------")
print(" Windows-Macchanger by Flo Faber")
print("---------------------------------\n")

print("Loading registry keys... ", end="")

while True:
    try:
        driverdesc = ""
        netid = ""
        parent = str(winreg.EnumKey(key, i))
        if parent.startswith("0"):
            newkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, keypath + "\\" + parent, 0, winreg.KEY_READ)
            j = 0
            while True:
                try:
Ejemplo n.º 16
0
import os, sys, inspect
currentdir = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
packagesdir = os.path.join(currentdir, 'packages')
sys.path.insert(0, packagesdir)

import usb.util
from usb.util import CTRL_IN, CTRL_OUT, CTRL_TYPE_VENDOR, CTRL_RECIPIENT_DEVICE

# Duran Keeley
# Generate random MAC address

from randmac import RandMac
import re
example_mac = "000000000000"
generated_mac = RandMac(example_mac, True)
mystring = str(generated_mac)
mystring = mystring.upper()
StrGenerated_mac = re.sub("'", '', mystring)

# Previous backfile overrides
#BACKUP_EEPROM_FILENAME = "ax88179.bin"
from datetime import datetime
# current date and time for backup file
now = datetime.now()
BACKUP_EEPROM_FILE = "ax88179 "
BACKUP_EEPROM_FILETIME = now.strftime("%Y-%m-%d %H-%M-%S")
BACKUP_EEPROM_FILENAME = BACKUP_EEPROM_FILE + BACKUP_EEPROM_FILETIME + ".bin"

ASIX_VID = 0x0B95
AX_PID = 0x1790
Ejemplo n.º 17
0
def generate_devices(n, arr):
    for i in range(n):
        arr.append(Device(RandMac("00:00:00:00:00:00"), i))
Ejemplo n.º 18
0
    def connect_gateway_router(self,
                               lrouter=None,
                               lswitch=None,
                               lswitch_create_args={},
                               lnetwork_create_args={},
                               gw_cidr=None,
                               ext_cidr=None,
                               sandbox=None):

        # Create a join switch to connect the GW router to the cluster router.
        lswitch_args = copy.copy(lswitch_create_args)
        lswitch_args["start_cidr"] = gw_cidr if str(gw_cidr) else ""
        join_switch = self.create_lswitch(prefix="join_",
                                          lswitch_create_args=lswitch_args)

        # Create ports between the join switch and the cluster router.
        self.connect_lswitch_to_router(lrouter, join_switch)

        # Create a gateway router and bind it to the local chassis.
        gw_router = self.nbctl.lr_add("grouter_" + str(gw_cidr))
        self.nbctl.run("set Logical_Router {} options:chassis={}".format(
            gw_router["name"], sandbox["name"]))

        # Create ports between the join switch and the gateway router.
        gr_gw = netaddr.IPAddress(gw_cidr.last - 2) if gw_cidr else None
        grouter_port_join_switch = "grpj-" + str(
            gw_cidr) if gw_cidr else "grpj"
        grouter_port_join_switch_ip = '{}/{}'.format(gr_gw, gw_cidr.prefixlen)
        self.nbctl.lr_port_add(gw_router["name"], grouter_port_join_switch,
                               RandMac(), grouter_port_join_switch_ip)
        self.nbctl.ls_port_add(join_switch["name"],
                               "jrpg-" + join_switch["name"],
                               grouter_port_join_switch)

        # Create an external switch connecting the gateway router to the
        # physnet.
        lswitch_args["start_cidr"] = ext_cidr if str(ext_cidr) else ""
        ext_switch = self.create_lswitch(prefix="ext_",
                                         lswitch_create_args=lswitch_args)
        self.connect_lswitch_to_router(gw_router, ext_switch)
        self.create_phynet(ext_switch,
                           lnetwork_create_args.get("physnet", "providernet"))

        cluster_cidr = lnetwork_create_args.get("cluster_cidr", "")
        if cluster_cidr and gw_cidr:
            # Route for traffic entering the cluster.
            rp_gw = netaddr.IPAddress(gw_cidr.last - 1)
            self.nbctl.route_add(gw_router["name"], cluster_cidr, str(rp_gw))

        if ext_cidr:
            # Default route to get out of cluster via physnet.
            gr_def_gw = netaddr.IPAddress(ext_cidr.last - 2)
            self.nbctl.route_add(gw_router["name"], gw=str(gr_def_gw))

        # Force return traffic to return on the same node.
        self.nbctl.run(
            "set Logical_Router {} options:lb_force_snat_ip={}".format(
                gw_router["name"], str(gr_gw)))

        # Route for traffic that needs to exit the cluster
        # (via gw router).
        self.nbctl.route_add(lrouter["name"],
                             str(lswitch["cidr"]),
                             str(gr_gw),
                             policy="src-ip")

        # SNAT traffic leaving the cluster.
        self.nbctl.nat_add(gw_router["name"],
                           external_ip=str(gr_gw),
                           logical_ip=cluster_cidr)
Ejemplo n.º 19
0
import time, sys, random


def print_slow(str):
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(0.1)


initial_sequence_number_host_a = random.randrange(100, 999)
initial_sequence_number_host_b = random.randrange(100, 999)

bits = getrandbits(32)
host_a_source_addr = IPv4Address(bits)
host_a_source_mac = RandMac("00:00:00:00:00:00")
host_b_source_mac = RandMac("00:00:00:00:00:00")
bits = getrandbits(32)
host_b_source_addr = IPv4Address(bits)

print("host a: sending an arp request to host b", host_b_source_addr)
print("outgoing arp request:")
print_slow("...............\n")
time.sleep(1)

print("Source hardware address:", host_a_source_mac)
print("Source protocol address:", host_a_source_addr)
print("Target hardware address: 00:00:00:00:00:00")
print("Target protocol address:", host_b_source_addr)
time.sleep(2)
Ejemplo n.º 20
0
# sudo pip3 install randmac

from randmac import RandMac

print("Random mac address: ", RandMac())