Example #1
0
def portScan():
    host = input("Please enter the IP address you would like to port scan - ")
    nmap.scan(host, '21 -1000')
    print(nmap.command_line())
    
    for host in nmap.all_hosts():
        print('')
        print('Host : %s (%s)' % (host, nmap[host].hostname()))
        print('State : %s' % nmap[host].state())

    for protocol in nmap[host].all_protocols():
        print('')
        print('Protocol : %s' % protocol)

        portList = nmap[host][protocol].keys()
        for port in portList:
            print("port : %s\tstate : %s" % (port, nmap[host][protocol][port]["state"]))
Example #2
0
def create_task():
    if not request.json or not 'server' in request.json:
        abort(400)
    if not request.json or not 'portrange' in request.json:
        abort(400)
    nmap.scan(request.json['server'], request.json['portrange'])
    result = []

    for host in nmap.all_hosts():
        for proto in nmap[host].all_protocols():
            lport = nmap[host][proto].keys()
            lport.sort()
            for port in lport:
                result.append({
                    'portNumber':port,
                    'cpe':  nmap[host][proto][port]['cpe'],
                    'name': nmap[host][proto][port]['name'],
                    'product': nmap[host][proto][port]['product'],
                    'state': nmap[host][proto][port]['state']
                })
    return jsonify({'data': result}), 200
Example #3
0
def nmapThem(ip, port):

    ipaddr = ip
    port = port
    nmap = nmap.PortScanner()

    print(nmap.command_line())
    
    nmap.scan(ip, port)




    '''
    nm = nmap.PortScanner() # instantiate nmap.PortScanner object
    nm.scan('127.0.0.1', '22-443') # scan host 127.0.0.1, ports from 22 to 443
    nm.command_line() # get command line used for the scan : nmap -oX - -p 22-443 127.0.0.1
    nm.scaninfo() # get nmap scan informations {'tcp': {'services': '22-443', 'method': 'connect'}}
    nm.all_hosts() # get all hosts that were scanned
    nm['127.0.0.1'].hostname() # get one hostname for host 127.0.0.1, usualy the user record
    nm['127.0.0.1'].hostnames() # get list of hostnames for host 127.0.0.1 as a list of dict
    # [{'name':'hostname1', 'type':'PTR'}, {'name':'hostname2', 'type':'user'}]
    nm['127.0.0.1'].hostname() # get hostname for host 127.0.0.1
    nm['127.0.0.1'].state() # get state of host 127.0.0.1 (up|down|unknown|skipped)
    nm['127.0.0.1'].all_protocols() # get all scanned protocols ['tcp', 'udp'] in (ip|tcp|udp|sctp)
    nm['127.0.0.1']['tcp'].keys() # get all ports for tcp protocol
    nm['127.0.0.1'].all_tcp() # get all ports for tcp protocol (sorted version)
    nm['127.0.0.1'].all_udp() # get all ports for udp protocol (sorted version)
    nm['127.0.0.1'].all_ip() # get all ports for ip protocol (sorted version)
    nm['127.0.0.1'].all_sctp() # get all ports for sctp protocol (sorted version)
    nm['127.0.0.1'].has_tcp(22) # is there any information for port 22/tcp on host 127.0.0.1
    nm['127.0.0.1']['tcp'][22] # get infos about port 22 in tcp on host 127.0.0.1
    nm['127.0.0.1'].tcp(22) # get infos about port 22 in tcp on host 127.0.0.1
    nm['127.0.0.1']['tcp'][22]['state'] # get state of port 22/tcp on host 127.0.0.1 (open
    '''




        '''for host in nm.all_hosts():
Example #4
0
def nwap(ip):
    try:
        # *****Convert input into String ****
        sip = str(ip)

        # *****Contstructs Scan ****
        nmap.scan(sip, port) 

        # *****Displays Scanned Output ****
        pap = (nmap.command_line())
        sinfo = (nmap.scaninfo())

        # *****Converts Output to String ****
        spap = str(pap)
        sfo = str(sinfo)

        # **** Convert String to Bytes ****
        bpap = str.encode(spap)
        binfo = str.encode(sfo)

        # **** Displays Output ****
        print (bpap)
        print (binfo)
        
        # ***** Create File & Write Bianry to the File *****
        with io.FileIO('/Users/xyz/Desktop/outmap.txt', "a") as file:
            file.write(bpap)
            file.write(binfo)

    # ***** Needs to Close the Session *****
    except Exception as e:
        print ("*** Caught exception: %s: %s") % (e.__class__, e)
        try:
            f.close()
        except:
            pass
Example #5
0
 def observe(self):
     """ Does a scan of the local network and records connected devices. """
     out, err = nmap.scan()
     reports = str(out).split('Nmap scan report for ')
     now = time.time()
     device_reports = reports[1:]
     for device_report in device_reports:
         ip = device_report.split('\\n')[0]
         mac = self.get_mac_address(device_report)
         description = self.get_device_description(device_report)
         data = {
             'ip': ip,
             'mac': mac,
             'time': now,
             'description': description
         }
         address = 'http://' + settings.webservice_host + '/connections'
         requests.post(address, json=data)
import nmap
count = 0
ip_open = []
with open("ip.txt", "r") as f:
    ip_list = f.read().splitlines()
    print(ip_list)
nmap = nmap.PortScanner()
for ip in ip_list:
    resp = nmap.scan(ip, "80")
    if resp['scan'][ip]['tcp'][80]['state'] == "open":
        count += 1
        ip_open.append(ip)
print '{} hosts open on port {} from total {} hosts'.format(
    count, 80, len(ip_list))
print 'The hosts with opened ports are : {}'.format(ip_open)
Example #7
0
import nmap  # import nmap.py module

nmap = nmap.PortScanner()
host = '127.0.0.1'
nmap.scan(host, '1-1024')
print nmap.command_line()
print nmap.scaninfo()

for host in nmap.all_hosts():
    print('Host : %s (%s)' % (host, nmap[host].hostname()))
    print('State : %s' % nmap[host].state())
for proto in nmap[host].all_protocols():
    print('Protocol : %s' % proto)

listport = nmap[host]['tcp'].keys()
listport.sort()

for port in listport:
    print('port : %s\tstate : %s' % (port, nmap[host][proto][port]['state']))
Example #8
0
device_ip = network_utils.get_interface_ip(net_iface_name)
subnet_mask = network_utils.get_interface_subnet_mask(net_iface_name)

print('Calculating subnet ip and subnet prefix...')
subnet_ip = device_ip.bitwise_and(subnet_mask)
mask_length = subnet_mask.get_num_starting_ones()

host_range = IPv4CIDR(subnet_ip, mask_length)
print('Host Range: {}'.format(host_range.get_string_representation()))

# Get hostnames and ip addresses for devices on network
print('Beginning scan loop...')
while True:
    print('Scanning subnet...')

    nmap_devices = nmap.scan(host_range)
    arp_devices = arp.scan()

    for device in arp_devices.keys() - nmap_devices:
        print('Device missing from nmap scan: {}'.format(device))
        if not ping.host_is_up(IPv4Addr(device)):
            del arp_devices[device]
            print('Device {} not found'.format(device))
        else:
            print('Found device {}'.format(device))

    print('Found {} host(s) on subnet:'.format(len(arp_devices)))
    for ip in arp_devices:
        print('\t{}: {} {}'.format(
            ip, arp_devices[ip]['hostname'] if arp_devices[ip]['hostname'] else
            '(unknown hostname)', arp_devices[ip]['MAC']))
Example #9
0
	print "-" * 50
	return int( raw_input("Option: ") )

def output_format():
	subprocess.call('clear', shell=True)
	print "-" * 50
	print "\t Select an option:"
	print "\t\t1) Console"
	print "\t\t2) txt file"
	print "\t\t3) Back"
	print "-" * 50
	return int( raw_input("Option: ") )	

while True:
	option = print_menu()

	while option != 3:
		format = output_format()
		subprocess.call('clear', shell=True)
		if option == 1:
			scan(format)
		elif option == 2:
			sniffer(format)
		elif option == 3:
			sys.exit()
		else:
			print "Invalid option"
		raw_input("Enter to continue")
		break
	if option == 3:
		sys.exit()
Example #10
0
network = ipaddress.ip_network("%s/%s" % (addr, netmask), strict=False)

start = network.network_address + 1
end = network.broadcast_address

maclookup = MacLookup()
nmap = nmap.PortScanner()

#for ipint in range(int(start), int(end)):
for ipint in range(int(start), int(start) + 1):
    ip = ipaddress.IPv4Address(ipint)
    ipstr = str(ip)
    hosts_info[ipstr] = {}
    mac = arpreq.arpreq(ip)
    vendor = None

    if mac is not None:
        vendor = maclookup.lookup(mac)
        scan_result = {}
        nmap.scan(hosts=ipstr, ports='1-1000', arguments='-sS -O')
        scan_result['os'] = nmap[ipstr]['osmatch'][0]['name']
        scan_result['open_tcp'] = [p for p in nmap[ipstr]['tcp']]
        #nmap.scan(hosts=ipstr, ports='1-1000', arguments='-sU')
        #print(nmap[ipstr]['udp'])

    hardware_info = [mac, vendor]
    hosts_info[ipstr]['hardware'] = hardware_info
    hosts_info[ipstr]['scan_result'] = scan_result

pprint.pprint(hosts_info)
import nmap                         # import nmap.py module

nmap = nmap.PortScanner()
host = '127.0.0.1'
nmap.scan(host, '1-1024')
print nmap.command_line()
print nmap.scaninfo()

for host in nmap.all_hosts():
    print('Host : %s (%s)' % (host, nmap[host].hostname()))
    print('State : %s' % nmap[host].state())
for proto in nmap[host].all_protocols():
    print('Protocol : %s' % proto)

listport = nmap[host]['tcp'].keys()
listport.sort()

for port in listport:
    print('port : %s\tstate : %s' % (port, nmap[host][proto][port]['state']))
Example #12
0
def main():
    nmap = nmap.PortScanner()
    data = nmap.scan('127.0.0.1','22-443')
    return jsonify({'data': data}), 201
Example #13
0
import socket
import ipcalc
import nmap

print('amazing super scan')

nmap = nmap.PortScanner() 
host = 
nmap.scan(host, '1-443') 

for host in nmap.all_hosts(): 
    print('Host : %s (%s)' % (host, nmap[host].hostname())) 
    print('State : %s' % nmap[host].state()) 

    # print('Host :' + nm[str(host)].hostname())
   #  print('State : %s' % nm[str(host)].state())
    for proto in nmap[str(host)].all_protocols():
        print('----------')
        print('Protocol : %s' % proto)

        lport = nmap[str(host)][proto].keys()
        lport.sort()
        for port in lport:
            print ('port : %s\tstate : %s' % (port, nmap[str(host)][proto][port]['state']))    





  
Example #14
0
    #print(select[1])
    return select[1]


def getSubnet(ip_addr):
    #print(ip_addr)
    ip_addr = '.'.join(ip.split('.')[:-1]) + '.*'
    return ip_addr


#### Main
#Get ip
ip = getInterfaces()
print('Scanning', getSubnet(ip), '...')
print('It will take some time to scan, please wait !')
scan_result = nmap.scan(getSubnet(ip))
hostlist = sorted(nmap.all_hosts(),
                  key=socket.inet_aton)  # sort the ip address

tb_host = pt.PrettyTable()
tb_top_ports = pt.PrettyTable()

tb_host.field_names = [
    'IP', 'MAC Address', 'OS Name', 'OS Accuracy', 'OS Family', 'Reason'
]
tb_top_ports.field_names = [
    'Port', 'Service', 'Protocol', 'State', 'Reason', 'Reason TTL'
]

for host in hostlist:
    inquirer_choice = []