• Uncategorized

About linux : How-do-I-pass-a-variable-to-a-bash-alias-easier-nmap-scanning-Function-alias-script…-duplicate

Question Detail

Been poking around for a bit trying to find a straight answer but VScode keeps giving me grief when checking the syntax and the alias doesn’t seem to work.

I often switch between networks with devices that aren’t easily discoverable and their IP addresses often change. I’ve found myself using nmap to quickly scan the network devices for the ports I’m looking for (e.g. 22 open ssh when working with a pi).

For example…

qmap11='nmap -sn'
qmap21='nmap -sn'
qmap31='nmap -sn'

As you can imagine this isn’t the cleanest way to do this, and I want to run something like the following

$ qmap 3
# to run nmap -sn


$ qmap ip
# to run something like nmap -sn [whatever subnet I'm on]
# so I don't have to first check what the network is

I’ve been tinkering with building a function… but want to figure this out first.

Other Posts:

Alias with variable in bash

Linux bash script to extract IP address

Which terminal command to get just IP address and nothing else?

How to detect the OS from a Bash script?

Make a Bash alias that takes a parameter?

Theser other posts definitely hint at what I’m tryingn to figure out.

Question Answer

It’s just a function.

qmap() {
   nmap -sn "192.168.$1.1/24"

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.