Sitemap

AnonSurf: Adding IP to terminal prompt

4 min readJul 17, 2025

--

Press enter or click to view image in full size

If you are using AnonSurf, or a VPN, and want to be aware of your current public IP then consider this short guide to adding your public IP to the terminal prompt.

Press enter or click to view image in full size

AnonSurf

AnonSurf was a cool feature in ParrotOS. One click privacy, all traffic routed through TOR. AnonSurf appears to be missing in some versions of ParrotOS. With a simple script you can add it to Debian flavor linux distributions (Kali, Parrot, Debian, Ubuntu, etc.)

This article isn’t about installing AnonSurf, but rather to display one’s public IP on the command prompt.

This article expects anonsurf to be installed on your Linux distro.

Why?

People have different reasons for privacy. For me, when I run an OSINT exercise for an employer or client, I don’t want to leave my IP footprint on a website I’m investigating.

Shell Scripts

I’m using four shell scripts:

  • anonsurf_start.sh
  • anonsurf_stop.sh
  • getpubip.sh
  • changepubip.sh

The contents of each are below. Each script is saved where systemctl can easily access (/usr/local/bin):

anonsurf_start.sh

#!/bin/bash

/usr/bin/anonsurf start

/usr/local/bin/getpubip.sh

anonsurf_stop.sh

#!/bin/bash

/usr/bin/anonsurf stop

/usr/local/bin/getpubip.sh

getpubip.sh

This one is a bit different, I’m sending the output to a txt file. Here’s the reason: you won’t want to run the call to anonsurf each time the prompt renders. If you do that you will quickly get rate limited. It’s also very slow, so the prompt will hang until it gets a response back.

If we save the IP address value to a flat file, and then reference the flat file in the .bashrc to display the public IP, we don’t get rate limited and we get a rapid response for the prompt to render.

#!/bin/bash

anonsurf myip > /usr/local/pubip.txt

changepubip.sh

#!/bin/bash

anonsurf change

I’m using anonsurf for all functions here, including getting and changing the public IP.

Service

Using sytemctl I setup a new service called anonsurf (/etc/systemd/system/anonsurf.service) and it looks like this:

[Unit]
Description=Anonsurf

[Service]
ExecStart=/usr/local/bin/anonsurf_start.sh
ExecStop=/usr/local/bin/anonsurf_stop.sh
Type=simple # Or forking, oneshot, etc., depending on your script's behavior
RemainAfterExit=yes
User=root
Group=root

[Install]
WantedBy=multi-user.target

The service has references to start and stop the service (seen above). As anonsurf must be run as root, I’ve added the User and Group settings.

Get Brian’s stories in your inbox

Join Medium for free to get updates from this writer.

Once setup, run:

sudo systemctl daemon-reload

Followed by:

sudo systemctl enable anonsurf

.bashrc changes

If you want your IP listed from ifconfig, then I’d recommend Fahmi J’s article on doing just that, as it was the inspiration for my work here.

The problem with ifconfig is that it doesn’t list the public IP for AnonSurf, and potentially other proxy solutions.

Our script above (getpubip.sh) it is set to run this command:

anonsurf myip > /usr/local/pubip.txt

This will save output like:

My ip is:

66.66.66.164

----------------------------------------------------------------------

To capture this into the terminal prompt, I added the following .bashrc changes:

function get_ip(){
default_ip=$(cat /usr/local/pubip.txt | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n 1)
echo "$default_ip"
}

Search in the .bashrc for “If this is an xterm” under that statement is a value defined: PS1=… comment out what’s there and add this version:

PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\033[0;31m\]\[\033[1;97m\]"\`get_ip\`"\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]\\$\[\e[0m\] "

Save and run:

source .bashrc

It’s basically the same parrot prompt, with an additional call to the get_ip function defined above. It also adds a space after the $ in the prompt.

Testing

To test the prompt gets the public IP, try starting the service:

sudo systemctl start anonsurf

Check the status with:

sudo systemctl status anonsurf

If all is good, it shoud be all green. Note any errors in the status output and resolve as necessary.

If it worked correctly the scripts should have created a pubip.txt file in /usr/local. That’s also the file .bashrc is pulling from. Check the file to make sure it looks good.

The prompt should pick up when you hit enter, or run any command. It will pull in and parse the IP address in /usr/local/pubip.txt.

Crontabs

We’re almost done. You might want to rotate your IP, this can be done through a crontab. You also will need to setup a regular check on the public IP.

Rotating IP Addresses

This can be done manually by running anonsurf change. We can set it up on a schedule by adding something like this to the crontab:

*/10 * * * * /usr/local/bin/changeip.sh

Pulling the Public IP

Another crontab can be added in order to pull the public IP on a regular basis:

*/10 * * * * /usr/local/bin/getpubip.sh

All Done

You can start and stop anonsurf as a typical service:

sudo systemctl start anonsurf

# or

sudo systemctl stop anonsurf

When running, it will pull your public IP based on the crontab interval and also attempt to change the public IP at a set interval as well.

NOTE: There are points of failure. If the crontab doesn’t update and you get a stale public IP in the text file. Always keep in mind to check the real values of the anonsurf public IP state.

--

--

Brian
Brian

Written by Brian

Cybersecurity professional (Blue and Red team)