Saturday, February 15, 2014

pwgen Script - Linux


A simple script I created that asks a character length and outputs random characters to use as a password. The script uses pwgen. (Password generator) This is useful if you're using Openbox and want pwgen on the right click menu, or have a hard time remembering the command. You will be asked how long long you want the password to be, then it will display a random output with special characters included.

Video tutorial/in action: Here

1. Open Terminal and enter:
sudo apt-get install pwgen
2. Followed by 
touch ~/script.sh && chmod +x ~/script.sh
3. Open the file manager. Right click on script.sh, go to Open with and select your editor.

4. Add this in, then save and close.
#clear   #Used if opened from the terminal
read -p "Character Length: " number
clear
echo
echo
pwgen -y -1 "$number"
echo
echo
5. The script can be opened in the terminal.
sh ~/script.sh

Using Openbox's menu to execute the script
1. In the terminal type:
obmenu
2. Enter a name for the label. (This is what shows up when you right click) I used pwgen.

3. Add this to Execute at the bottom
terminator --command="sh ~/script.sh; echo; ${SHELL:-bash}"
Replace ~/script.sh to the location and file name of your choice

4. Click Save at the top. Right click on the desktop, then select pwgen to launch the script.

Wednesday, February 12, 2014

Block local ip or a website - Linux Script

This is a simple script that uses the tcpkill to block internet access to a specific machine on a local network or a website from the entire network. When a website is blocked, you will still have access to it. If the target is blocked, they will still show an active connection in the tray.  -- Use with LAN connection works, WLAN doesn't work all of the time.

The tutorial at the bottom integrates the script into the right click menu of Openbox.

Video tutorial / in action: Here

1. In the terminal enter sudo apt-get -y install dsniff --no-install-recommends
2. Enter  nano ~/script.sh
3. Paste this in


LanInt="eth0"

function BlockConnection
{
if [ -n "$(pidof tcpkill)" ]; then killall tcpkill >/dev/null 2>/dev/null; fi  #Stop

#Option Menu
if [ -z "$(pidof tcpkill)" ]; then clear; echo; echo
echo "    Block Website/Webpage or IP Address"
echo
echo "    (1) IP   (2) Website   (3) Cancel"
echo
read -p "                 > " BlockCheck
if [[ "$BlockCheck" == "1" ]]; then clear; echo; echo; echo; read -p "       IP Address: " BlockSite     #IP
elif [[ "$BlockCheck" == "2" ]]; then clear; echo; echo; echo; read -p "       Website/Webpage: " BlockSite #Website/Webpage
elif [[ "$BlockCheck" == "3" ]]; then MainMenu
else BlockConnection; fi

#IP
if [[ "$BlockCheck" == "1" ]]; then clear; tcpkill -i $LanInt -9 host "$BlockSite"; fi

#WebSite/Webpage
if [[ "$BlockCheck" == "2" ]]; then 
if [[ "$BlockSite" == *"www."* ]]; then BlockSite="$BlockSite"; else BlockSite="www.$BlockSite"; fi #Add www.  (If needed)
clear; tcpkill -i $LanInt -9 host "$BlockSite"; fi
fi
 }

BlockConnection


4. Save the script
5. Lastly type sudo chmod +x script.sh


eth0 for wired connection or wlan0 for wireless
6. Open a terminal and enter:
sudo sh ~/script.sh

Using Openbox's menu to execute the script
1. In the terminal type in obmenu
2. Enter a name for the label. This is what show up when you right click. I used Bock Connection.
3. Add this to Execute at the bottom
 terminator --command="sudo sh ~/script.sh"
Replace ~/script.sh to the location and file name of your choice
4. Click Save at the top. Right click on the desktop, then select Block Connection to launch the script