def __init__(self, api_url=None, api_user=None, api_password=None, config_name=None): """ :Parameters: - `api_url` : string - `api_user` : string - `api_password` : string - `config_name` : string Example: >>> from proteus.api import ProteusClientApi >>> pc=ProteusClientApi( 'http://proteus.domain.tld/', 'username', 'password', 'proteus_configuration_object_name') """ super(ProteusClient, self).__init__(api_url, api_user, api_password) self._config_name = config_name self._configuration = None self._get_configuration() self._dns = DNS(self)
def h_flow_filters_dst(self): if not self._h_flow_filters_dst: lst_filters = [] for data_unit in self.data: for edge in self.outgoing_edges: if edge.type is SecurityGroupMapEdge.Type.IP: h_filter = HFlow.Tunnel.Traffic() h_filter.info = [data_unit, edge] h_filter.dns_src = DNS(data_unit["dns"]) if "ip" not in data_unit: ip = AWSAPI.find_ips_from_dns(h_filter.dns_src)[0] else: ip = data_unit["ip"] h_filter.ip_src = ip h_filter.ip_dst = edge.dst h_filter.service_dst = edge.service lst_filters.append(h_filter) else: pdb.set_trace() self._h_flow_filters_dst = lst_filters return self._h_flow_filters_dst
def __init__(self, con=None): self._con = con self._dns = DNS(self) self._dhcp = DHCP(self) self._ftp = PureFTP(self) self._network = Network(self) self._firewall = Firewall(self)
def register_node(self, domain, port): """ ノードを追加する 失敗したら例外を返す :param ip :param port """ # 名前解決 try: ip = DNS.domain_to_ip(domain) except: ip = domain try: # uuidを取得 response = requests.get(f'http://{ip}:{port}/uuid') if response.status_code == 200: self.nodes[f'{ip}:{port}'] = {} uuid = response.json()['uuid'] self.nodes[f'{ip}:{port}']['uuid'] = uuid else: raise Exception("GET uuid failed") # publickeyを取得 response = requests.get(f'http://{ip}:{port}/publickey') if response.status_code == 200: key = response.json()['key'] self.nodes[f'{ip}:{port}']['key'] = key else: raise Exception("GET pubkey failed") except: raise Exception("Cannot register node")
def __init__(self, device=None, interfaces=None, include_shared_config=True): ''' @param device: dict to identify the ASA device, passed in from device_script APIs @param interfaces: dict physical interfaces names passed in from device_script APIs @param include_shared_config: boolean Flag to indicate if the function configuration should be modified. ''' DMObject.__init__(self, ifc_key=DeviceModel.__name__) self.device = device self.interfaces = interfaces self.sts_table = {} self.label2nameif = {} #cache of label to nameif map 'All the stuff defined in vnsMDevCfg section of device_specification.xml' self.register_child(Vifs()) self.register_child(DMList('VLAN', Vlan)) self.register_child(VxlanPort('vxlan_port')) self.register_child(NVE('NVE')) self.register_child(TVIs()) self.register_child(DMList('ENCAPASS', EncapAss)) self.register_child(DMList('InterfaceConfig', InterfaceConfig)) self.register_child(PortChannelMembers()) self.register_child(HostObjects()) self.register_child(SubnetObjects()) self.register_child(RangeObjects()) self.register_child(FQDNObjects()) self.register_child(ICMP4Objects()) self.register_child(ICMP6Objects()) self.register_child(ProtocolObjects()) self.register_child(TCPObjects()) self.register_child(UDPObjects()) self.register_child(NetworkObjectGroups()) self.register_child(ServiceObjectGroups()) self.register_child(AccessListList()) self.register_child( AccessListDeployment()) # Must follow AccessListList self.register_child(ClusterConfig()) self.register_child(LoggingConfig()) self.register_child(FailoverConfig()) self.register_child(AccessGroupGlobal()) self.register_child(Timeouts()) self.register_child(BasicThreatDetection()) self.register_child(AdvancedThreatDetection()) self.register_child(ScanningThreatDetection()) self.register_child(NetFlowObjects()) self.register_child(IPAudit()) self.register_child(NTP()) self.register_child(DNS()) self.register_child(SmartCallHome()) self.register_child(GlobalServicePolicyContainer()) 'Child for vsnGrpCfg element' if include_shared_config: self.register_child(SharedConfig())
def get_ec2_instances_h_flow_destinations(self): sg_map = self.prepare_security_groups_mapping() total_count = 0 for ec2_instance in self.ec2_instances: for endpoint in ec2_instance.get_security_groups_endpoints(): print(endpoint) hflow = HFlow() tunnel = hflow.Tunnel() tunnel.traffic_start = HFlow.Tunnel.Traffic() tunnel.traffic_end = HFlow.Tunnel.Traffic() end_point_src = hflow.EndPoint() if "ip" not in endpoint: print("ec2_instance: {} ip not in interface: {}/{}".format(ec2_instance.name, endpoint["device_name"], endpoint["device_id"])) continue end_point_src.ip = endpoint["ip"] tunnel.traffic_start.ip_src = endpoint["ip"] if "dns" in endpoint: #print("ec2_instance: {} dns not in interface: {}/{}".format(ec2_instance.name, endpoint["device_name"], endpoint["device_id"])) end_point_src.dns = DNS(endpoint["dns"]) tunnel.traffic_start.dns_src = DNS(endpoint["dns"]) end_point_src.add_custom("security_group_id", endpoint["sg_id"]) hflow.end_point_src = end_point_src end_point_dst = hflow.EndPoint() hflow.end_point_dst = end_point_dst tunnel.traffic_start.ip_dst = tunnel.traffic_start.any() hflow.tunnel = tunnel lst_flow = sg_map.apply_dst_h_flow_filters_multihop(hflow) lst_resources = self.find_resources_by_ip(lst_flow[-1]) pdb.set_trace() total_count += 1 print("{}: {}".format(len(lst_flow), lst_flow)) #pdb.set_trace() print("Total hflows count: {}".format(total_count)) pdb.set_trace() self.find_end_point_by_dns()
def _getFactoryEnabledClasses(self): return (("", "UCI", UCI()), ("", "DNS", DNS()), ("", "DHCP", DHCP()), ("", "PureFTP", PureFTP()), ("", "Network", Network()), ("", "Firewall", Firewall()), ("", "OpenWRTManager", OpenWRTManager()))
from cliente import Cliente from servidor import Servidor from mensagem import Mensagem from dns import DNS from time import sleep dns = DNS() s1 = Servidor('gmail', dns) s2 = Servidor('hotmail', dns) s3 = Servidor('yahoo', dns) dns.cadastrarServidor('gmail', s1) dns.cadastrarServidor('hotmail', s2) dns.cadastrarServidor('yahoo', s3) gabriel = Cliente("Gozales", "burrito", s1) caio = Cliente("Caio", "zica", s1) alexandre = Cliente("Alexandre", "thegreat", s2) cachorrao = Cliente("cachorrao", "lenis", s2) marcao = Cliente("berranteiro", "tbt", s3) miguel = Cliente("Vinicius", "PAIton", s3) m1 = Mensagem('gabriel', 'alexandre', 'hotmail.com', "teste", "teste") m2 = Mensagem('gabriel', 'cachorrao', 'hotmail.com', "Saaalve", "Saalve cachorro!") m3 = Mensagem('alexandre', 'marcao', 'yahoo.com.br', "Sdds", "Liberdade vai canta") m4 = Mensagem('cachorrao', 'miguel', 'yahoo.com', "Aula LP 2", "Ex dificil pra p***") m5 = Mensagem('miguel', 'alexandre', 'hotmail.com', "Aula LP 2", "Ex dificil pra p***") m6 = Mensagem('miguel', 'gabriel', 'gmail.com', "Aula LP 2",
def testmethod_10(): print "Method testmethod_10 in class testclass_4" print "Method GW empty, DNS same subnet, DNS service down, WWW hostname in class testclass_4" __author__ = 'bzhang4' scheme = Scheme.find('wlan0','1234') time.sleep(5) scheme.activate() down_dns = DNS() down_dns.set_dns_stop() ui_operation = UITest() ui_operation.static_config('192.168.2.33','255.255.255.0','0.0.0.0','192.168.2.100') time.sleep(5) ui_operation.ping_config_retest('a.fnet.com') browser = webdriver.Firefox() browser.get('http://172.16.9.9') time.sleep(3) ipConfig_value = browser.find_element_by_id("ipConfigHeadIcon").get_attribute('src') GW_value = browser.find_element_by_id("gateHeadIcon").get_attribute('src') cloud_value = browser.find_element_by_id("wwwHeadIcon").get_attribute('src') print(cloud_value) known_ipConfig_value = 'http://172.16.9.9/images/dhcpgreen.png' known_GW_value = 'http://172.16.9.9/images/gatewayblack.png' known_cloud_value = 'http://172.16.9.9/images/cloudred.png' assert ipConfig_value == known_ipConfig_value assert GW_value == known_GW_value assert cloud_value == known_cloud_value ser = serial.Serial() ser.baudrate = 115200 ser.port = '/dev/ttyUSB0' ser.open() assert ser.isOpen() ser.write('leds\n') ser.inWaiting() b = ser.read(110) str1 = bytes.decode(b) print(str1) dhcp_led = 'DHCP:\tGREEN' GW_led = 'GW:\tNONE' #www_led = 'WWW:\tRED' assert str1.find(dhcp_led) != -1 assert str1.find(GW_led) != -1 up_dns = DNS() up_dns.set_dns_start() dhcp_test = UITest() dhcp_test.dhcp_config_retest() cloudHeadIcon_value = browser.find_element_by_id('cloudHeadIcon').is_displayed() print(cloudHeadIcon_value) browser.quit() if cloudHeadIcon_value == False: assert True else: assert False MONGOHQ_URL='mongodb://*****:*****@c494.candidate.42.mongolayer.com:10494/linksprinter-new-test' DATABASE = 'linksprinter-new-test' mongoClient = MongoClient(MONGOHQ_URL) linksprinter = mongoClient[DATABASE] collection=linksprinter.results print(collection) a = collection.find({"unit_mac": "00C017-090909","cached": True}).sort([("created_at",pymongo.DESCENDING)]).limit(1) aa = dict(a[0]) dhcp_color = aa['ipConfigColor'] www_color = aa['wwwColor'] print('The ipConfigColor is %s' % dhcp_color) print('The wwwColor is %s' % www_color) assert dhcp_color == u'green' assert www_color == u'red'
from restunl.device import IOL from globals import * from dns import DNS import file_io import re DEFAULT_INTF = 'Loopback0' DNS_RESOLVER = DNS(file_io.read_yaml('{}/ip.yml'.format(TMP_DIR))) class IncorrectEndpointFormat(Exception): pass class Endpoint(object): def __init__(self, text): self.dev, self.intf, self.ip = '', '', '' self.node = None if DNS_RESOLVER.is_ip(text): self.dev, self.intf = DNS_RESOLVER.get(text) self.ip = text else: self.dev, self.intf = self._parse(text) self.ip = DNS_RESOLVER.get(self.dev, self.intf) @staticmethod def _parse(text): separators = ',|\s' seq = [word.strip() for word in re.split(separators, text)] if len(seq) > 1: return seq[0], Endpoint.expand(seq[1])
def get(self): domain = self.request.get("d") use_hosts = self.request.get_range("uh", default=0) use_cache = self.request.get_range("uc", default=0) # Compatible with dnsrelay 1.0, all query string as domain if (domain == ""): domain = self.request.query_string if len(domain) == 0: self.response.out.write(CANT_RESOLVE) return domain = DNS.unshake(domain) if not DNS.isValidHostname(domain): logging.error("Invalid domain name: %s" % domain) self.response.out.write(CANT_RESOLVE) return # Query from hosts datastore if g_config.use_hosts or use_hosts: dns = DNSHosts() ret = dns.lookup(domain) if (ret != CANT_RESOLVE): self.response.out.write(ret) return # Query from cache if g_config.use_cache or use_cache: ret = g_cache.lookup(domain) if (ret != CANT_RESOLVE): self.response.out.write(ret) return # Query from web try: dns = DNSWebLookupserverOcom() ret = dns.lookup(domain) if (ret != CANT_RESOLVE): self.response.out.write(ret) if g_config.cache_web_query: g_cache.update(domain, ret, True) return except WebRequestError: #logging.error("Web request error") pass try: dns = DNSWebBlokeOcom() ret = dns.lookup(domain) if (ret != CANT_RESOLVE): self.response.out.write(ret) if g_config.cache_web_query: g_cache.update(domain, ret, True) return except WebRequestError: #logging.error("Web request error") pass if g_config.cache_web_query: g_cache.update(domain, ret, False) # Can't be resovled self.response.out.write(CANT_RESOLVE) return
def get_all_addresses(self): return [DNS(self.dns_name)]