add a command to each command (e.g. proxychains each command by default)

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
How can I execute each command pre-appended with another one?
Example when I run:
nmap -p 80 host
I want it to run
proxychains nmap -p 80 host
even when I do not add proxychains intentionally.
In other words: can I alias all commands at once with proxychains pre-appended?
Bonus if this is something I can switch on/off.
bash command-line proxychains
add a comment |Â
up vote
1
down vote
favorite
How can I execute each command pre-appended with another one?
Example when I run:
nmap -p 80 host
I want it to run
proxychains nmap -p 80 host
even when I do not add proxychains intentionally.
In other words: can I alias all commands at once with proxychains pre-appended?
Bonus if this is something I can switch on/off.
bash command-line proxychains
Each and every command? Not just everynmapbut everything?
â ilkkachu
Dec 16 '17 at 14:51
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How can I execute each command pre-appended with another one?
Example when I run:
nmap -p 80 host
I want it to run
proxychains nmap -p 80 host
even when I do not add proxychains intentionally.
In other words: can I alias all commands at once with proxychains pre-appended?
Bonus if this is something I can switch on/off.
bash command-line proxychains
How can I execute each command pre-appended with another one?
Example when I run:
nmap -p 80 host
I want it to run
proxychains nmap -p 80 host
even when I do not add proxychains intentionally.
In other words: can I alias all commands at once with proxychains pre-appended?
Bonus if this is something I can switch on/off.
bash command-line proxychains
edited Dec 18 '17 at 22:16
Gilles
507k12010031530
507k12010031530
asked Dec 16 '17 at 14:11
AK_
75738
75738
Each and every command? Not just everynmapbut everything?
â ilkkachu
Dec 16 '17 at 14:51
add a comment |Â
Each and every command? Not just everynmapbut everything?
â ilkkachu
Dec 16 '17 at 14:51
Each and every command? Not just every
nmap but everything?â ilkkachu
Dec 16 '17 at 14:51
Each and every command? Not just every
nmap but everything?â ilkkachu
Dec 16 '17 at 14:51
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
Would it work to just run a full shell under proxychains? Assuming it can deal with processes started by the shell properly.
You could do with just
$ÃÂ proxychains bash
and exit the shell at will.
But if you really want to, you can abuse the DEBUG trap (with extdebug set) to mangle the commands the shell runs. This would run every command with time:
$ shopt -s extdebug
$ d() eval "time $BASH_COMMAND"; return 1;
$ÃÂ trap d DEBUG
$ sleep 2
real 0m2.010s
user 0m0.000s
sys 0m0.000s
$ trap - DEBUG # turn it off, this still prints the 'time' output
But the tricky part here is that it will also affect builtins, like trap or shopt themselves, so you'd probably want to add some exceptions for those... Also, stuff like cd somedir would turn into proxychains cd somedir, which probably will not work. This would also affect everything started from within functions etc. Maybe it's better to just have the function use proxychains only for those commands known to need it.
this is genius solution! I wish I can give you 100 points for it. Thank you!
â AK_
Dec 17 '17 at 10:29
bonus of bonus: is there a way I can temporarily ask bash to escape one command to run it withoutproxychains? example I don't wantlsto be slow and wait forproxychains
â AK_
Dec 17 '17 at 10:31
1
@AK_, with the shell under proxychains, I don't think so. With the DEBUG trap you could of course do anything, but listing the programs you want to use proxychains with, or the ones without it might get annoying. Which leads me to think if it would be easier to justalias p=proxychainsand then go withp nmap...when you need it...
â ilkkachu
Dec 17 '17 at 11:03
add a comment |Â
up vote
1
down vote
You can just create an alias for your current sesion.
alias nmap="proxychains nmap"
Everytime you write nmap, it would be as writting "proxychains nmap".
You can turn it off with:
unalias nmap
You could also create a shell script to manage this. Just add it to your bashrc
function prefix
if [ $2 != "with" ]; then
echo "You have to prefix something with something"
return
fi
echo "alias $1 = $3 $1"
alias $1="$3 $1"
function unprefix sed "s/=.b.*b /='/g")
So you can do:
prefix nmap with proxychains
unprefix nmap
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Would it work to just run a full shell under proxychains? Assuming it can deal with processes started by the shell properly.
You could do with just
$ÃÂ proxychains bash
and exit the shell at will.
But if you really want to, you can abuse the DEBUG trap (with extdebug set) to mangle the commands the shell runs. This would run every command with time:
$ shopt -s extdebug
$ d() eval "time $BASH_COMMAND"; return 1;
$ÃÂ trap d DEBUG
$ sleep 2
real 0m2.010s
user 0m0.000s
sys 0m0.000s
$ trap - DEBUG # turn it off, this still prints the 'time' output
But the tricky part here is that it will also affect builtins, like trap or shopt themselves, so you'd probably want to add some exceptions for those... Also, stuff like cd somedir would turn into proxychains cd somedir, which probably will not work. This would also affect everything started from within functions etc. Maybe it's better to just have the function use proxychains only for those commands known to need it.
this is genius solution! I wish I can give you 100 points for it. Thank you!
â AK_
Dec 17 '17 at 10:29
bonus of bonus: is there a way I can temporarily ask bash to escape one command to run it withoutproxychains? example I don't wantlsto be slow and wait forproxychains
â AK_
Dec 17 '17 at 10:31
1
@AK_, with the shell under proxychains, I don't think so. With the DEBUG trap you could of course do anything, but listing the programs you want to use proxychains with, or the ones without it might get annoying. Which leads me to think if it would be easier to justalias p=proxychainsand then go withp nmap...when you need it...
â ilkkachu
Dec 17 '17 at 11:03
add a comment |Â
up vote
4
down vote
accepted
Would it work to just run a full shell under proxychains? Assuming it can deal with processes started by the shell properly.
You could do with just
$ÃÂ proxychains bash
and exit the shell at will.
But if you really want to, you can abuse the DEBUG trap (with extdebug set) to mangle the commands the shell runs. This would run every command with time:
$ shopt -s extdebug
$ d() eval "time $BASH_COMMAND"; return 1;
$ÃÂ trap d DEBUG
$ sleep 2
real 0m2.010s
user 0m0.000s
sys 0m0.000s
$ trap - DEBUG # turn it off, this still prints the 'time' output
But the tricky part here is that it will also affect builtins, like trap or shopt themselves, so you'd probably want to add some exceptions for those... Also, stuff like cd somedir would turn into proxychains cd somedir, which probably will not work. This would also affect everything started from within functions etc. Maybe it's better to just have the function use proxychains only for those commands known to need it.
this is genius solution! I wish I can give you 100 points for it. Thank you!
â AK_
Dec 17 '17 at 10:29
bonus of bonus: is there a way I can temporarily ask bash to escape one command to run it withoutproxychains? example I don't wantlsto be slow and wait forproxychains
â AK_
Dec 17 '17 at 10:31
1
@AK_, with the shell under proxychains, I don't think so. With the DEBUG trap you could of course do anything, but listing the programs you want to use proxychains with, or the ones without it might get annoying. Which leads me to think if it would be easier to justalias p=proxychainsand then go withp nmap...when you need it...
â ilkkachu
Dec 17 '17 at 11:03
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Would it work to just run a full shell under proxychains? Assuming it can deal with processes started by the shell properly.
You could do with just
$ÃÂ proxychains bash
and exit the shell at will.
But if you really want to, you can abuse the DEBUG trap (with extdebug set) to mangle the commands the shell runs. This would run every command with time:
$ shopt -s extdebug
$ d() eval "time $BASH_COMMAND"; return 1;
$ÃÂ trap d DEBUG
$ sleep 2
real 0m2.010s
user 0m0.000s
sys 0m0.000s
$ trap - DEBUG # turn it off, this still prints the 'time' output
But the tricky part here is that it will also affect builtins, like trap or shopt themselves, so you'd probably want to add some exceptions for those... Also, stuff like cd somedir would turn into proxychains cd somedir, which probably will not work. This would also affect everything started from within functions etc. Maybe it's better to just have the function use proxychains only for those commands known to need it.
Would it work to just run a full shell under proxychains? Assuming it can deal with processes started by the shell properly.
You could do with just
$ÃÂ proxychains bash
and exit the shell at will.
But if you really want to, you can abuse the DEBUG trap (with extdebug set) to mangle the commands the shell runs. This would run every command with time:
$ shopt -s extdebug
$ d() eval "time $BASH_COMMAND"; return 1;
$ÃÂ trap d DEBUG
$ sleep 2
real 0m2.010s
user 0m0.000s
sys 0m0.000s
$ trap - DEBUG # turn it off, this still prints the 'time' output
But the tricky part here is that it will also affect builtins, like trap or shopt themselves, so you'd probably want to add some exceptions for those... Also, stuff like cd somedir would turn into proxychains cd somedir, which probably will not work. This would also affect everything started from within functions etc. Maybe it's better to just have the function use proxychains only for those commands known to need it.
edited Dec 17 '17 at 10:57
answered Dec 16 '17 at 14:55
ilkkachu
49.9k674137
49.9k674137
this is genius solution! I wish I can give you 100 points for it. Thank you!
â AK_
Dec 17 '17 at 10:29
bonus of bonus: is there a way I can temporarily ask bash to escape one command to run it withoutproxychains? example I don't wantlsto be slow and wait forproxychains
â AK_
Dec 17 '17 at 10:31
1
@AK_, with the shell under proxychains, I don't think so. With the DEBUG trap you could of course do anything, but listing the programs you want to use proxychains with, or the ones without it might get annoying. Which leads me to think if it would be easier to justalias p=proxychainsand then go withp nmap...when you need it...
â ilkkachu
Dec 17 '17 at 11:03
add a comment |Â
this is genius solution! I wish I can give you 100 points for it. Thank you!
â AK_
Dec 17 '17 at 10:29
bonus of bonus: is there a way I can temporarily ask bash to escape one command to run it withoutproxychains? example I don't wantlsto be slow and wait forproxychains
â AK_
Dec 17 '17 at 10:31
1
@AK_, with the shell under proxychains, I don't think so. With the DEBUG trap you could of course do anything, but listing the programs you want to use proxychains with, or the ones without it might get annoying. Which leads me to think if it would be easier to justalias p=proxychainsand then go withp nmap...when you need it...
â ilkkachu
Dec 17 '17 at 11:03
this is genius solution! I wish I can give you 100 points for it. Thank you!
â AK_
Dec 17 '17 at 10:29
this is genius solution! I wish I can give you 100 points for it. Thank you!
â AK_
Dec 17 '17 at 10:29
bonus of bonus: is there a way I can temporarily ask bash to escape one command to run it without
proxychains ? example I don't want ls to be slow and wait for proxychainsâ AK_
Dec 17 '17 at 10:31
bonus of bonus: is there a way I can temporarily ask bash to escape one command to run it without
proxychains ? example I don't want ls to be slow and wait for proxychainsâ AK_
Dec 17 '17 at 10:31
1
1
@AK_, with the shell under proxychains, I don't think so. With the DEBUG trap you could of course do anything, but listing the programs you want to use proxychains with, or the ones without it might get annoying. Which leads me to think if it would be easier to just
alias p=proxychains and then go with p nmap... when you need it...â ilkkachu
Dec 17 '17 at 11:03
@AK_, with the shell under proxychains, I don't think so. With the DEBUG trap you could of course do anything, but listing the programs you want to use proxychains with, or the ones without it might get annoying. Which leads me to think if it would be easier to just
alias p=proxychains and then go with p nmap... when you need it...â ilkkachu
Dec 17 '17 at 11:03
add a comment |Â
up vote
1
down vote
You can just create an alias for your current sesion.
alias nmap="proxychains nmap"
Everytime you write nmap, it would be as writting "proxychains nmap".
You can turn it off with:
unalias nmap
You could also create a shell script to manage this. Just add it to your bashrc
function prefix
if [ $2 != "with" ]; then
echo "You have to prefix something with something"
return
fi
echo "alias $1 = $3 $1"
alias $1="$3 $1"
function unprefix sed "s/=.b.*b /='/g")
So you can do:
prefix nmap with proxychains
unprefix nmap
add a comment |Â
up vote
1
down vote
You can just create an alias for your current sesion.
alias nmap="proxychains nmap"
Everytime you write nmap, it would be as writting "proxychains nmap".
You can turn it off with:
unalias nmap
You could also create a shell script to manage this. Just add it to your bashrc
function prefix
if [ $2 != "with" ]; then
echo "You have to prefix something with something"
return
fi
echo "alias $1 = $3 $1"
alias $1="$3 $1"
function unprefix sed "s/=.b.*b /='/g")
So you can do:
prefix nmap with proxychains
unprefix nmap
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can just create an alias for your current sesion.
alias nmap="proxychains nmap"
Everytime you write nmap, it would be as writting "proxychains nmap".
You can turn it off with:
unalias nmap
You could also create a shell script to manage this. Just add it to your bashrc
function prefix
if [ $2 != "with" ]; then
echo "You have to prefix something with something"
return
fi
echo "alias $1 = $3 $1"
alias $1="$3 $1"
function unprefix sed "s/=.b.*b /='/g")
So you can do:
prefix nmap with proxychains
unprefix nmap
You can just create an alias for your current sesion.
alias nmap="proxychains nmap"
Everytime you write nmap, it would be as writting "proxychains nmap".
You can turn it off with:
unalias nmap
You could also create a shell script to manage this. Just add it to your bashrc
function prefix
if [ $2 != "with" ]; then
echo "You have to prefix something with something"
return
fi
echo "alias $1 = $3 $1"
alias $1="$3 $1"
function unprefix sed "s/=.b.*b /='/g")
So you can do:
prefix nmap with proxychains
unprefix nmap
edited Dec 16 '17 at 15:07
answered Dec 16 '17 at 14:29
WooWapDaBug
16411
16411
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f411260%2fadd-a-command-to-each-command-e-g-proxychains-each-command-by-default%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Each and every command? Not just every
nmapbut everything?â ilkkachu
Dec 16 '17 at 14:51