hostscan

NMAP Host Generator
git clone git@jamesshield.xyz:repos/hostscan.git
Log | Files | Refs | README | LICENSE

README.md (4916B)


      1 # README
      2 
      3 This is a simple script that performs an nmap scan on a destination address, parses the XML result into a Python Map and can transform the data for use in creating host files, Ansible host manifests or drive an inventory database using MongoDB.
      4 
      5 
      6 We leverage DocOpt for command processing:
      7 
      8 
      9 ```
     10 Usage: nmap-scan [options] <network>
     11 
     12 Options:
     13     --mongo-host MONGO_HOST                Mongo Host(default: localhost)
     14     --mongo-port MONGO_PORT                Mongo Port(default: 3001)
     15     --database DB                          Add records to mongo db
     16     --collection COLLECTION                Add records to mongo collection
     17     -H, --hosts                            Print *nix hosts file format [default].
     18     -R, --raw                              Print raw collection database
     19     -I, --insert                           Performs insert instead of in place update
     20     -S, --snmp                             Make SNMP calls
     21     -A, --ansible                          Make Ansible inventory
     22     -D, --debug                            Print debug information
     23 
     24 ```
     25 
     26 
     27 As an example to run a scan on a 24bit subnet you could run:
     28 ```
     29 nmap-scan.py -H 192.168.1.0/24
     30 ```
     31 
     32 ```
     33 192.168.1.124	192-168-1-124
     34 192.168.1.113	192-168-1-113
     35 192.168.1.10	takagi
     36 192.168.1.1	192-168-1-1
     37 192.168.1.101	192-168-1-101
     38 192.168.1.100	192-168-1-100
     39 192.168.1.168	192-168-1-168
     40 192.168.1.149	192-168-1-149
     41 192.168.1.115	192-168-1-115
     42 192.168.1.227	192-168-1-227
     43 192.168.1.209	192-168-1-209
     44 192.168.1.217	192-168-1-217
     45 ```
     46 
     47 Generate an Ansible hosts file
     48 
     49 ```
     50 [hosts]
     51 192-168-1-10	ansible_ssh_user=root	ansible_ssh_pass=#password#
     52 192-168-1-1	ansible_ssh_user=root	ansible_ssh_pass=#password#
     53 192-168-1-101	ansible_ssh_user=root	ansible_ssh_pass=#password#
     54 192-168-1-113	ansible_ssh_user=root	ansible_ssh_pass=#password#
     55 192-168-1-168	ansible_ssh_user=root	ansible_ssh_pass=#password#
     56 192-168-1-149	ansible_ssh_user=root	ansible_ssh_pass=#password#
     57 192-168-1-115	ansible_ssh_user=root	ansible_ssh_pass=#password#
     58 192-168-1-227	ansible_ssh_user=root	ansible_ssh_pass=#password#
     59 192-168-1-209	ansible_ssh_user=root	ansible_ssh_pass=#password#
     60 192-168-1-217	ansible_ssh_user=root	ansible_ssh_pass=#password#
     61 ```
     62 
     63 
     64 More detail nmap scan:
     65 
     66 ```
     67  '192-168-1-115': {'_id': '192-168-1-115',
     68                    'ip': '192.168.1.115',
     69                    'mac': None,
     70                    'name': '192-168-1-115',
     71                    'services': [{'portid': '80',
     72                                  'product': 'HP Photosmart 7510 series printer http config',
     73                                  'protocol': 'tcp',
     74                                  'service_name': 'http'},
     75                                 {'portid': '139',
     76                                  'product': None,
     77                                  'protocol': 'tcp',
     78                                  'service_name': 'netbios-ssn'},
     79                                 {'portid': '443',
     80                                  'product': 'HP Photosmart 7510 series printer http config',
     81                                  'protocol': 'tcp',
     82                                  'service_name': 'http',
     83                                  'ssl_cn': None,
     84                                  'ssl_orgname': None,
     85                                  'ssl_valid': None}],
     86                    'vendor': None},
     87  '192-168-1-124': {'_id': '192-168-1-124',
     88                    'ip': '192.168.1.124',
     89                    'mac': None,
     90                    'name': '192-168-1-124',
     91                    'vendor': None},
     92  '192-168-1-149': {'_id': '192-168-1-149',
     93                    'ip': '192.168.1.149',
     94                    'mac': None,
     95                    'name': '192-168-1-149',
     96                    'vendor': None},
     97  '192-168-1-168': {'_id': '192-168-1-168',
     98                    'ip': '192.168.1.168',
     99                    'mac': None,
    100                    'name': '192-168-1-168',
    101                    'services': [{'portid': '111',
    102                                  'product': None,
    103                                  'protocol': 'tcp',
    104                                  'service_name': 'rpcbind'}],
    105                    'vendor': None},
    106  '192-168-1-209': {'_id': '192-168-1-209',
    107                    'ip': '192.168.1.209',
    108                    'mac': None,
    109                    'name': '192-168-1-209',
    110                    'services': [{'portid': '111',
    111                                  'product': None,
    112                                  'protocol': 'tcp',
    113                                  'service_name': 'rpcbind'}],
    114                    'vendor': None},
    115  '192-168-1-217': {'_id': '192-168-1-217',
    116                    'ip': '192.168.1.217',
    117                    'mac': None,
    118                    'name': '192-168-1-217',
    119                    'vendor': None},
    120  '192-168-1-227': {'_id': '192-168-1-227',
    121                    'ip': '192.168.1.227',
    122                    'mac': None,
    123                    'name': '192-168-1-227',
    124                    'vendor': None}}
    125 ```