Last active
January 7, 2022 20:17
-
-
Save FromeXo/54a610f003671c3a0685bd66dbad5d14 to your computer and use it in GitHub Desktop.
Quick and dirty node script for seaching private ips.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const exec = require('child_process').exec; | |
| const options = { | |
| net: '192.168.0', | |
| start: 1, | |
| end: 256, | |
| verpose: false | |
| }; | |
| process.argv.slice(2).forEach( (val, index, array) => { | |
| const i = index + 3; | |
| switch(val) { | |
| case '--start': | |
| options.start = process.argv[i]; | |
| break; | |
| case '--end': | |
| options.end = process.argv[i] + 1; | |
| break; | |
| case '--net': | |
| options.net = process.argv[i]; | |
| break; | |
| case '--verbose': | |
| options.verbose = true; | |
| break; | |
| case '--help': | |
| console.log('[command] [--flag] [flag-value].... eg: [command] --net 192.168.0'); | |
| console.log('--net'); | |
| console.log('--start'); | |
| console.log('--end'); | |
| } | |
| }); | |
| console.info('Pinging ' + options.net + '.' + options.start + ' - ' + options.net + '.' + (options.end-1)); | |
| for (let i=options.start; i < options.end; i++) { | |
| let ip = options.net + '.' + i; | |
| if ( options.verbose ) { | |
| console.info('ping -n 3 -4 ' + ip); | |
| } | |
| exec('ping -n 3 -4 ' + ip, (err, stdout) => { | |
| if ( err ) { | |
| if ( options.verbose ) { | |
| console.error(err); | |
| } | |
| return; | |
| } | |
| if (/Reply/g.test(stdout)) { | |
| const pattern = /\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}/g | |
| const result = stdout.match(pattern); | |
| console.log('Awnser on: ',result[0]); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment