def do_test(n_data_packets, cc, add_events):
    """
    The test has 2 hosts connected by a link, and one flow.
    """
    em = EventManager(logging=False)
    host_1 = Host(em, 'H1', debug=False)
    host_2 = Host(em, 'H2', debug=False)
    sr = SeqNumberRecorder('S', host_2)
    l1_a = Link(em, 'L1_a', host_1, sr, DATA_PACKET_SIZE * 1000, 0.01,
                5 * DATA_PACKET_SIZE, debug=False)
    l1_b = Link(em, 'L1_b', host_2, host_1, DATA_PACKET_SIZE * 1000, 0.01,
                5 * DATA_PACKET_SIZE, debug=False)
    host_1.link = l1_a
    host_2.link = l1_b
    flow = Flow(em, 'F1', host_1, host_2, n_data_packets * DATA_PACKET_SIZE, 1,
                cc, debug=False)

    add_events(em, host_1, host_2, sr, l1_a, l1_b, flow)
    em.run()

    assert sr.seqs == set(range(n_data_packets + 1))
    # print('Src send first unacked', flow.src.send_first_unacked, 'Src send next', flow.src.send_next, 'Dst receive next', flow.dst.receive_next)
    assert flow.src.last_seq_number == n_data_packets
    assert flow.src.send_first_unacked == n_data_packets + 1
    assert flow.src.send_next == n_data_packets + 1
    assert flow.dst.receive_next == n_data_packets + 1
Пример #2
0
 def get_host_after_rules(self):
     self.hosts = []
     rules_dict = self.get_rules()
     for host in self.host_list:
         if rules_dict.has_key(host[1]) or host[0] in rules_dict.values():
             if rules_dict[host[1]] == host[0]:
                 #logger.info("ip: {0} match right mac:{1}!".format(host[0],host[1]))
                 self.hosts.append(Host(host[0], host[1], '在白名单中'))
             else:
                 self.hosts.append(Host(host[0], host[1], '与白名单不符'))
                 #logger.info("ip: {0} match wrong mac:{1}!".format(host[0],host[1]))
         else:
             self.hosts.append(Host(host[0], host[1], '不在白名单中'))
Пример #3
0
    def __init__(self):
        self.width = WIDTH
        self.height = HEIGHT
        self.host_quantity = HOSTS_QUANTITY
        self.signal_range = SIGNAL_RANGE
        
        self.hosts = list()

        ## HOSTS INSTANTIATION ##
        # generates a random position and creates a host with it 
        print(f"\nGenerating positions for {HOSTS_QUANTITY} hosts in a map {WIDTH}x{HEIGHT} Km...", end=" ")
        positions = utils.generate_coordinates(HOSTS_QUANTITY, WIDTH, HEIGHT)
        for position in positions:
            self.hosts.append(Host(position, SIGNAL_RANGE))
        print(f"{HOSTS_QUANTITY} hosts were created.")

        ## ROUTER INSTANTIATION ##
        print("Creating router...", end=" ")
        router = Router(self.hosts)
        print("Router created.")

        # gives an list of near active hosts for each host
        print("Running Hello for each host...", end=" ")
        router.hello()
        print("Host Hello status complete.\n")
    def create_host(self, environment, immune_halftime=2):
        """
		This creates a host inside a specified environment.
		"""
        from host import Host

        host = Host(environment=environment, immune_halftime=immune_halftime)
Пример #5
0
    def __init__(self,
                 task_id,
                 hostname,
                 host,
                 rank,
                 task_conf,
                 shared_dir=None,
                 user_name="beeuser"):
        # Basic configurations
        self.__status = ""
        self.__hostname = hostname
        self.rank = rank
        self.master = ""

        # Job configuration
        self.task_id = task_id
        self.task_conf = task_conf

        # Host machine
        self.__node = host
        self.host = Host(host)

        # Shared resourced
        self.shared_dir = shared_dir
        self.user_name = user_name

        # Output color list
        self.__output_color_list = [
            "magenta", "cyan", "blue", "green", "red", "grey", "yellow"
        ]
        self.output_color = "cyan"
        self.error_color = "red"
Пример #6
0
 def __init__(self, default_target: BuildTarget, hosts_filename: str,
              compressor: Compressor, parser: Parser):
     self.compressor = compressor
     self.root_target = default_target
     self.hosts = []
     try:
         hosts_file_lines = open(hosts_filename).readlines()
         for line in hosts_file_lines:
             if line.strip().startswith('#'):
                 continue
             try:
                 line = line.strip()
                 self.hosts.append(Host(line.split()[0], line.split()[1]))
             except KeyError:
                 pass
     except FileNotFoundError:
         raise FileNotFoundError(f"Error! Hosts file cannot be found")
     self.active_hosts: List[Host] = [
         HostLocal() for _ in range(config.MAX_LOCAL_PROCESSES)
     ]
     self.available_hosts: List[Host] = [
         HostLocal() for _ in range(config.MAX_LOCAL_PROCESSES)
     ]
     self.busy_hosts: List[Host] = []
     self.lock = asyncio.Lock()
     self.host_cond_var = asyncio.Condition()
     self.parser = parser
Пример #7
0
 def setUp(self):
     self.val1 = 1000.1
     self.val2 = 1000.2
     self.val3 = 255
     self.host1 = Host(self.val1)
     self.host1.update(self.val2)
     self.host1.update(self.val3)
Пример #8
0
def main():
    fetcher = DataFetcher("cookies.txt")
    data = fetcher.getItems(
        "https://www.couchsurfing.com/members/hosts?utf8=%E2%9C%93&search_query=Curitiba%2C+Brazil&latitude=-25.4244287&longitude=-49.2653819&country=Brazil&region=south-america&date_modal_dismissed=true&arrival_date=&departure_date=&num_guests=1&has_references=1&can_host%5Baccepting_guests%5D=1&last_login=Anytime&join_date=Anytime&gender=All&min_age=&max_age=&languages_spoken=&interests=&smoking=No+Preference&radius=10&keyword=&host_sort=Best+Match&button=&perPage=100",
        "h3",
        className="-name")
    usuarios = [
        Host(u.a.string, u.a['href'][len("/users/"):], u.a['href'])
        for u in data
    ]

    arquivo = open("usuarios.csv", "w")
    arquivo_usuarios = csv.DictWriter(arquivo,
                                      fieldnames=["nome", "id", "endereco"],
                                      lineterminator='\n')
    arquivo_usuarios.writeheader()

    for user in usuarios:
        arquivo_usuarios.writerow({
            'nome': user.nome,
            'id': user.id,
            'endereco': user.endereco.strip()
        })

    arquivo.close()
Пример #9
0
 def prepare_host(self, params):
     host = Host(1)
     host.hMin = params[0]
     host.hMax = params[1]
     host.hSum = params[2]
     host.hCount = params[3]
     return host
Пример #10
0
    def getHostList(self, cidade, kwargs={}, output="hosts.csv", per_page=100):
        """
            Obtem uma lista de hosts de um local no expedia
        """
        with open(output, "w", encoding='utf-8') as arquivo:
            arquivo_usuarios = csv.DictWriter(arquivo, fieldnames=["nome","id","endereco","cidade"], lineterminator='\n')
            arquivo_usuarios.writeheader()
            # url para pegat via html V1
            # url = u"https://www.couchsurfing.com/members/hosts?utf8=%E2%9C%93&search_query={}&latitude={}&longitude={}&country=Brazil&region=south-america&date_modal_dismissed=true&arrival_date=&departure_date=&num_guests=1&has_references=1&can_host%5Baccepting_guests%5D=1&last_login=Anytime&join_date=Anytime&gender=All&min_age=&max_age=&languages_spoken=&interests=&smoking=No+Preference&radius=10&keyword=&host_sort=Best+Match&button=&perPage={}".format(urllib.parse.quote(cidade.nome), cidade.latitude, cidade.longitude, per_page)
            url = u"https://www.couchsurfing.com/api/web/users/search?controller=user_profiles&action=hosts&city={}&page=1&perPage={}&latitude={}&longitude={}&has_references=1&search_query={}".format(urllib.parse.quote(cidade.nome), per_page, cidade.latitude, cidade.longitude, urllib.parse.quote(cidade.endereco))
            # url = u"https://www.couchsurfing.com/api/web/users/search?utf8=%E2%9C%93&search_query={}&latitude={}&longitude={}&date_modal_dismissed=true&arriva%20l_date=&departure_date=&num_guests=1&has_references=1&can_host%5Baccepting_guests%5D=1&last_login=Anytime&join_date=Anytime&gender=All&min_age=&max_age=&languages_spoken=&interests=&smoking=No%20%20Preference&radius=10&keyword=&host_sort=Best%20Match&button=&perPage={}&controller=user_profiles&action=hosts&page=1&city={}".format(urllib.parse.quote(cidade.nome), cidade.latitude, cidade.longitude, per_page, urllib.parse.quote(cidade.nome))
            print(cidade.nome)
            data = self.getJson(url)["users"]

            for user in data:
                nome = user["publicName"]
                id = user["id"]
                endereco = user["profileLink"]
            # for user in data:
            #   nome = user.find("span", "user-card__name").string
            #   id = user.find("a", "user-card__content")['href'][len("/people/"):]
            #   endereco = user.find("a", "user-card__content")['href']

                host = Host(nome, id, endereco, cidade)
                print("{} {} {} {} ".format(host.nome, host.id, host.endereco, host.cidade.nome))
                arquivo_usuarios.writerow({"nome" : host.nome, "id" : host.id, "endereco" : host.endereco, "cidade" : host.cidade.nome})
Пример #11
0
    def post(self):
        self.set_header("Content-Type", 'application/json; charset="utf-8"')
        switch = self.request.headers.get("X-switch-name")
        params = json.loads(self.request.body.decode())
        print "Discovered %s from %s with %s" % (params["ip"], switch,
                                                 params["mac"])

        host = None
        # host already known
        if params["ip"] in self.topology.hosts.keys():
            self.set_status(200)
            host = self.topology.hosts[params["ip"]]
            host.update(mac=params["mac"],
                        switch=params["switch"],
                        switch_port=params["switch_port"])
        # host just discovered
        else:
            self.set_status(201)
            host = Host(ip=params["ip"],
                        mac=params["mac"],
                        switch=params["switch"],
                        switch_port=params["switch_port"])
            self.topology.hosts[params["ip"]] = host
            ready(self.topology)

        # return the uuid for later use
        result = {"uuid": str(host.uuid)}
        self.finish(json.dumps(result))
Пример #12
0
 def __init__(self, host=None):
     if not host:
         host = Host()
     self._parser = None
     self._host = host
     self._buildenv = None
     self._device = None
Пример #13
0
def current_host(config):
    hosts = {}
    import sys
    import inspect
    import pkgutil
    import importlib
    from host import Host

    # Try to get the current host as specified in the config file
    # Otherwise resort to the Default host
    h_config = config.get_global_config()['host']
    host_class = h_config['type']
    #Iterate through all the members of this class
    module_names = [name for _, name, _ in pkgutil.iter_modules([__name__])]
    for mod in module_names:
        importlib.import_module(__name__ + '.' + mod)

    for mod in module_names:
        for name, obj in inspect.getmembers(sys.modules[__name__ + '.' + mod]):
            if inspect.isclass(obj):
                hosts[obj.__name__] = obj

    if host_class in hosts:
        return hosts[host_class](h_config)
    else:
        host = Host(h_config)

    return host
Пример #14
0
def process_hosts(data, args):
    hosts = []
    for item in data:
        u = item.rstrip('\n')
        if 'http' not in u:
            print(
                FAIL +
                "No protocol supplied for host: {0}. Use format http(s)://<host> Skipping..."
                .format(u))
            continue
        try:
            host = Host(store_headers=args['--headers'],
                        follow_redirects=args['--follow-redirects'])
            host.set_url(u)
            hosts.append(host)
            print(SUCCESS + "Adding host to list: {0}".format(host.get_url()))

        except IndexError:  # URL doesn't begin with a protocol
            print(
                FAIL +
                "No protocol supplied for host: {0}. Use format http(s)://<host>. Skipping..."
                .format(u))
            continue

    return hosts
Пример #15
0
 def __init__(self, subnet, starting_host, ending_host):
     self.working_queue = multiprocessing.Queue()
     self.done_queue = multiprocessing.Queue()
     for host in xrange(starting_host, ending_host + 1):
         address = '%s.%d' % (subnet, host)
         # Add the host scanner to the working queue
         self.working_queue.put(Host(host, address))
Пример #16
0
 def __init__(self, ipAddr, port):
     '''
     Constructor: takes IP address and port of the ViPR instance. These are
     needed to make http requests for REST API
     '''
     self.__ipAddr = ipAddr
     self.__port = port
     self.__hostObject = Host(self.__ipAddr, self.__port)
Пример #17
0
    def create_host(self):
        #        with self.lock:
        self.count = self.count + 1

        host = Host(self.count)
        super(HostList, self).append(host)

        return host
Пример #18
0
def get_list_host(response_query_str: List[Dict[Text, Any]]):
    if response_query_str is None:
        return list()
    response_query: List[Host] = list(
        map(
            lambda h: Host(h['ip'], h['mac'], h['vendor'], h['date'], h[
                'network'], h['description'], h['id']), response_query_str))
    return sorted(list(set(response_query)))  # REMOVE DUPLICATES
Пример #19
0
 def test_host_class(self):
     host_name = "hostname"
     host = Host(host_name)
     self.assertTrue(host.name == host_name)
     self.assertTrue(
         dateutil.parser.parse(host.last_updated).day ==
         datetime.today().day)
     self.assertTrue(len(host.software) == 0)
Пример #20
0
def main(host=None, argv=None):
    host = host or Host()
    args = parse_args(argv)
    if args.version:
        host.print_out(VERSION)
        return 0
    if args.grammar_cmd is None and args.grammar_file is None:
        host.print_err('must specify one of -c or -g')
        return 1

    try:
        grammar_txt, grammar_fname, err = grammar_from_args(host, args)
        if err:
            host.print_err(err)
            return 1

        if args.pretty_print or args.compile_grammar:
            if args.pretty_print:
                out, err = print_grammar(grammar_txt, grammar_fname)
            else:
                if args.inline_compiled_parser_base:
                    base = (host.read(host.dirname(__file__),
                                      'compiled_parser_base.py'))
                else:
                    base = None
                out, err = compile_grammar(grammar_txt, grammar_fname,
                                           args.compiled_parser_class_name,
                                           args.compiled_parser_package_name,
                                           base)

            if err:
                host.print_err(err)
                return 1
            if args.output:
                host.write(args.output, out)
            else:
                host.print_out(out, end='')
            return 0

        input_txt, input_fname, err = input_from_args(host, args)
        if err:
            host.print_err(err)
            return 1

        out, err = parse(grammar_txt, input_txt, grammar_fname, input_fname,
                         args.use_compiled_grammar_parser)
        if err:
            host.print_err(err)
        if out:
            if args.output:
                host.write(args.output, str(out))
            else:
                host.print_out(str(out), end='')
        return 0 if err is None else 1

    except KeyboardInterrupt:
        host.print_err('Interrupted, exiting ..')
        return 130  # SIGINT
Пример #21
0
    def __get_hostdetails(self, dns_blockip):
        """
        Get Host Name and IP address for __dnsserver_blacklist and __dnsserver_whitelist
        """
        host = Host(dns_blockip)                   #Declare host class
        logger.info(f'Hostname: {host.name}, IP Address: {host.ip}')

        #Setup the template strings for writing out to black/white list files
        [self.__dnsserver_blacklist, self.__dnsserver_whitelist] = self.__services.get_dnstemplatestr(host.name, host.ip)
Пример #22
0
def host_process_cli(config, auth, opt):
    if opt['--delimiter'] is None:
        delimiter = " "
    else:
        delimiter = opt['--delimiter']

    if opt['--format'] is None:
        o_format = "text"
    else:
        o_format = opt['--format']

    n = Host(
        hostname=config.host,
        auth=auth,
        o_format=o_format,
        delimiter=delimiter
    )

    if opt['list'] is True:
        n.list_hosts()
    elif opt['search'] is True:
        n.search(
            name=opt['<name>'],
            site=opt['<site>'],
        )
    elif opt['get'] is True:
        network = opt['<network>']
        n.get(network)
    elif opt['fixedaddresses'] is True:
        network = opt['<network>']
        n.fixedaddresses(network)
    elif opt['create'] is True:
        name = opt['<name>']
        ipv4addrs = opt['<ipv4addrs>']
        mac = opt['<mac>']

        n.create_host(
            name,
            ipv4addrs,
            mac,
            disable=disable,
            members=members,
        )
        if n.api_out.has_error:
            print "Unable to Create Host: %s" % network
            sys.exit(2)
        else:
            print "Host Created Successfully"
            n.get(network)
    if opt['delete'] is True:
        network = opt['<network>']
        if network is not None:
            ret = n.delete_network(
                network,
            )
            if ret is False:
                print "Unable to delete network"
Пример #23
0
    def loadHostList(self, filename):
        """
            Carrega um arquivo csv com dados de cidades
        """
        with open(filename, "r", encoding="utf-8") as arquivo:
            reader = csv.DictReader(arquivo)
            self.hosts = [ Host(row["nome"], row["id"], row["endereco"], row["cidade"]) for row in reader ]

        print("{} hosts loaded".format(len(self.hosts)))
Пример #24
0
    def __init__(self, filename, duration):
        self.filename = filename
        # the duration of the simulation, in number of timesteps
        self.duration = int(duration / globals.dt)
        # Import the network object parameters
        with open(self.filename) as f:
            network_objects = json.load(f)
        # Create links
        for l in network_objects['links']:
            # Clear the variable
            link = None

            # Add to idmapping
            link = Link(l['id'], l['connection1'], l['connection2'], \
                        l['rate'], l['delay'], l['buffersize'], l['track1'] == 1, \
                        l['track2'] == 1)
            globals.idmapping['links'][l['id']] = link

        # Create hosts
        for h in network_objects['hosts']:
            # Clear the variable
            host = None

            # Add to idmapping
            host = Host(h['id'], h['linkid'])
            globals.idmapping['hosts'][h['id']] = host

        # Create routers
        if network_objects['routers'] != [{}]:
            for r in network_objects['routers']:
                # Clear the variable
                router = None

                # Get the list of links connected to each router
                link_list = []
                for lin_id in r['links']:
                    link_list.append(globals.idmapping['links'][lin_id])

                # Initialize router and add to idmapping
                router = Router(r['id'], link_list)
                globals.idmapping['routers'][r['id']] = router

        # Create flows
        for f in network_objects['flows']:
            # Clear the variable
            flow = None

            # add to idmapping
            if f['congestion_control'] == 'reno':
                flow = Flow(f['id'], f['source'], f['destination'], f['amount'], \
                    f['start'], f['track'] == 1)
            else:
                flow = Flow_FAST(f['id'], f['source'], f['destination'], f['amount'], \
                    f['start'], f['track'] == 1)

            globals.idmapping['flows'][f['id']] = flow
Пример #25
0
 def generate_executor(cls, type=0, **kwargs):
     """
     Produce executor by its type
     :param type: 0 - physical host, 1 - virtual machine
     :param kwargs: executor properties
     :return: instance of executor
     """
     if type == 0:
         from host import Host
         return Host(**kwargs)
Пример #26
0
def ReadFile(name, cnt, cert, delay, prec):
    f = open(name, "r")
    arr = []
    bd = False

    for line in f:
        opt = line.split()
        if line == "\n" or len(opt) == 0:
            if (bd == False):
                bd = True
            else:
                k = Host(method, url, header, body, cnt, prec)
                arr.append(k)
                bd = False
        elif opt[0] == "GET" or opt[0] == "POST" or opt[0] == "HEAD" or opt[
                0] == "OPTIONS" or opt[0] == "PUT" or opt[0] == "DELETE":
            method = opt[0]
            url = opt[1]
            header = {}
            body = ""
        else:
            if bd == False:
                i = 1
                str = ""
                while i < len(opt):
                    if i == len(opt) - 1:
                        str = str + opt[i]
                    else:
                        str = str + opt[i] + " "
                    i += 1
                header[opt[0].replace(":", "")] = str
            else:
                body += line

    k = Host(method, url, header, body, cnt, prec)
    arr.append(k)
    '''
	for i in arr:
		g=SendData(i,delay,cnt,cert)
		i.time=g
	'''
    return arr
Пример #27
0
    def add_host(self, host_id, link, flows):
        """Adds a new host to the network.

        Args:
            host_id (str): The network address of the host.
            link (Link): The link that the host is connected to.
            flows (dict): All the flows that are going out of the host.

        """
        host = Host(self, host_id)
        self.nodes[host_id] = host
Пример #28
0
 def _rows(self):
     self._hosts = []
     for row in self._readlines(self.file_path):
         if row.startswith(r'#'):
             continue  # skip comments for now
         if len(row.split()) < 2:
             continue  # skip invalid rows
         ipaddress, hostname, aliases, comments = Hosts._process_row(row)
         host = Host(ipaddress, hostname, aliases, comments)
         self._hosts.append(host)
     return self._hosts
Пример #29
0
def addHost():
	print "Enter Host Ipv4 Address"
	ipadr = str(raw_input(prompt))

	print "Enter Comment/Note"
	note = str(raw_input(prompt))

	ip4 = buildIp(ipadr)
	host = Host(ip4, note)
	dal = Dal()
	dal.addHost(host)
	dal.save()
Пример #30
0
    def _parse_yaml(self, file_path):
        group = {}
        f = open(file_path)
        content = yaml.load(f)
        for key in content.keys():
            key_list = []
            list = content[key]
            for li in list:
                host = Host(li['host']['ip'], li['host']['ssh_username'], li['host']['ssh_password'], li['splunk_home'])
                key_list.append(host)
            group[key] = key_list

        return group