Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # DÉPENDANCES:
- # pip install termcolor
- # pip install nmap
- # pip install pyroute2
- from termcolor import colored
- from pyroute2 import IPRoute
- import nmap
- import subprocess
- nm = nmap.PortScanner()
- def changeIp(interface, ipadd):
- ip = IPRoute()
- print colored('Configuration IP ' + ipadd + ' sur interface ' + interface, 'blue')
- index = ip.link_lookup(ifname=interface)[0]
- ip.addr('add', index, address=ipadd, mask=24)
- ip.close()
- def scanSubnet(subnetToScan):
- print colored('scanning subnet' + subnetToScan, 'blue')
- nm.scan(hosts=subnetToScan, arguments='-n -sP -PE -PA21,23,80,3389')
- hosts_list = [(x, nm[x]['status']['state'], nm[x]['status']['state']) for x in nm.all_hosts()]
- for host in hosts_list:
- print colored("✔️ " + str(host[0]), 'green')
- def pingIpList(iplist):
- print colored('ping ips', 'blue')
- for ip in iplist:
- address = ip
- res = subprocess.call(['ping', '-c', '3', '-W', '1', address],stdout=subprocess.PIPE)
- if res == 0:
- print colored("✔️ " + address, 'green')
- elif res == 2:
- print colored("❌ " + address + " aucune réponse", 'yellow')
- else:
- print colored("❌ " + address, 'red')
- changeIp('enp9s0', '172.16.30.1')
- pingIpList(["8.8.8.8", "172.16.30.1"])
- scanSubnet('172.16.0.0/24')
- changeIp('enp9s0', '10.51.1.250')
- scanSubnet('10.51.1.0/24')
- changeIp('enp9s0', '10.200.100.250')
- scanSubnet('10.200.100.0/24')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement