def arp_scan(subnet): nm = PS() retadd = [] nm.scan(hosts=subnet, arguments="-sn") results = nm._scan_result['scan'] for i in results: if results[i]['status']['state'] == "up": retadd.append(i) return tuple(retadd)
def quick_scan(ip): nm = PS() ports = {} nm.scan(hosts=ip, arguments="--open") results = nm._scan_result['scan'] if 'tcp' in results[ip].keys(): ports['tcp'] = results[ip]['tcp'] pprint(ports['tcp']) if 'udp' in results[ip].keys(): ports['udp'] = results[ip]['udp'] pprint(ports['udp']) return ports
def load_instance_config(self, config): """ Attempt to load the results from the cache. If no cache exists, run a new scan and cache those results :param data: configuration data from the settings.py file :return: None """ global results # remove "/" from network name so we can use it for our cache cache_network_name = self.get_config_value("network").replace("/", "-") cache_key_name = "NmapDiscovery_%s" % cache_network_name # query the cache results = cache.get(cache_key_name) if results is None: print "No results found - performing new scan" ps = PortScanner() results = ps.scan(hosts=self.get_config_value("network"), arguments="-sP") cache.set(cache_key_name, results, int(self.get_config_value("cache_timeout"))) self.iterator = iter(results["scan"].iteritems()) return
def get_endpoint_by_id(self, endpoint_ip): """ for NmapDiscovery, id is always == endpoint_ip run a new scan only on that ip. Ignores cache :param endpoint_ip: :return: endpoint pyobject """ ps = PortScanner() r = ps.scan(hosts=endpoint_ip, arguments="-sP") print r return self.create_endpoint((endpoint_ip, r["scan"][endpoint_ip]))
def get_endpoint_by_id(self, endpoint_ip): """ for NmapDiscovery, id is always == endpoint_ip run a new scan only on that ip. Ignores cache :param endpoint_ip: :return: endpoint pyobject """ ps = PortScanner() r = ps.scan(hosts=endpoint_ip, arguments="-sP") print r return self.create_endpoint((endpoint_ip, r["scan"][endpoint_ip]))
def load_instance_config(self, config): """ Attempt to load the results from the cache. If no cache exists, run a new scan and cache those results :param data: configuration data from the settings.py file :return: None """ global results # remove "/" from network name so we can use it for our cache cache_network_name = self.get_config_value("network").replace("/", "-") cache_key_name = "NmapDiscovery_%s" % cache_network_name # query the cache results = cache.get(cache_key_name) if results is None: print "No results found - performing new scan" ps = PortScanner() results = ps.scan(hosts=self.get_config_value("network"), arguments="-sP") cache.set(cache_key_name, results, int(self.get_config_value("cache_timeout"))) self.iterator = iter(results["scan"].iteritems()) return