def main(): admin_username = raw_input("Enter Administrator Username [admin]:") admin_password = raw_input("Enter Administrator Password [22222]:") while True: ip_start = raw_input("Enter IP start:") if not ip_start: print '\033[1;31mIP Start Required\033[1;m' else: if validate_ip(ip_start): break else: print '\033[1;31mThis is not a valid IPv4 address\033[1;m' while True: ip_stop = raw_input("Enter IP stop:") if not ip_stop: print '\033[1;31mIP Stop Required\033[1;m' else: if validate_ip(ip_stop): break else: print '\033[1;31mThis is not a valid IPv4 address\033[1;m' if not admin_username: admin_username = "******" if not admin_password: admin_password = "******" #get the ip_start and stop and get a ip range r = IpRange(ip_start,ip_stop) for ip in r: check = Aastra_Check(ip,admin_username,admin_password) if check.check(): check.get_local_file() else: print "%s Is not an Aastra SIP Device"%ip
def main(): admin_username = raw_input("Enter Administrator Username [admin]:") admin_password = raw_input("Enter Administrator Password [22222]:") while True: ip_start = raw_input("Enter IP start:") if not ip_start: print '\033[1;31mIP Start Required\033[1;m' else: if validate_ip(ip_start): break else: print '\033[1;31mThis is not a valid IPv4 address\033[1;m' while True: ip_stop = raw_input("Enter IP stop:") if not ip_stop: print '\033[1;31mIP Stop Required\033[1;m' else: if validate_ip(ip_stop): break else: print '\033[1;31mThis is not a valid IPv4 address\033[1;m' if not admin_username: admin_username = "******" if not admin_password: admin_password = "******" #get the ip_start and stop and get a ip range r = IpRange(ip_start, ip_stop) for ip in r: check = Aastra_Check(ip, admin_username, admin_password) if check.check(): check.get_local_file() else: print "%s Is not an Aastra SIP Device" % ip
def validate_ipaddress(ip): return validate_ip(ip)
def add_host(self, ip, network): h = Host(ip=ip, network=network) self.stdout.write("%s adding\n" % ip) try: h.save() except IntegrityError, e: self.stderr.write("%s ERROR %s\n" % (ip, e)) def handle(self, *args, **options): try: net = Network.objects.get(slug=options['network']) except Network.DoesNotExist, e: try: net = Network.objects.get(name=options['network']) except Network.DoesNotExist, e: print("Network %s not found, try ./manage.py addnetwork <network>") return for target in args: if ipv6.validate_ip(target) or ipv4.validate_ip(target): self.add_host(target, net) elif ipv6.validate_cidr(target) or ipv6.validate_cidr(target): hosts = list(IpRange(target)) print hosts for host in hosts[1:-1]: self.add_host(host, net) else: hosts = resolve_dns(target) for host in hosts: self.add_host(host, net)
def ipv4_validation(self, val): return validate_ip(val)
'to the switch(es).') parser.add_argument('--creds_file', type=str, help='File containing ' 'list of credential pairs to try.') args = parser.parse_args() switch_ip = args.switch if args.user: password = getpass.getpass() elif args.creds_file and os.path.exists(args.creds_file): _creds_file = open(args.creds_file, 'r') for _line in _creds_file: username, password = _line.split(" ") password.rstrip() if ipv4.validate_ip(args.switch): # These cases are redundant. reduce this code!! try: main(args.config, args.user, password, switch_ip.rstrip()) except ConnectionFailure: print("There was a problem connecting to {}".format(switch_ip)) elif os.path.exists(args.switch): # get list of switches from the file and iterate through them. switch_list_file = open(switch_ip, 'r') print(switch_ip) for ip_addr in switch_list_file: try: print(ip_addr) main(args.config, args.user, password, ip_addr.rstrip()) except ConnectionFailure: print("There was a problem connecting to {}".format(ip_addr)) else: