Friday, November 19, 2010

Check that off my to do list.

So, it just goes to show that a simple google search could turn up an answer to most things.  In this case, a shell function I felt was missing.

That is, I wanted to be able to cd into a directory, and then have the files listed automatically. I had attempted to try this myself.  First thinking of trying an alias, then trying to write a shell script for it.

As I found out , and a forum poster pointed out, a shell script would print out the ls of the target directory, but the cd function would actually change the current working directory of the shell script, not the terminal that ran it.  It might be possible to write a script to change the calling terminal's current working directory, but it is beyond my scripting skills.

So, after googling here is what I found.

Add to your ~/.bashrc ( or if you have one,  ~/.bash_aliases ) file the line:

lcd() { cd ${1} ; ls ; }

To get a basic ls after a cd. Then restart your terminal, if you had one running, and give it a try.

Or if you are like me, you might want a more detailed ls after cd, so I implemented:
lcd() { cd ${1} ; ls -hl; }


 Which has it list details about the directory with filesize listed in k, M or G sizes. 



So, the googled idea is very elegant, and works well.  

Good night, and good luck.

Tuesday, November 16, 2010

Interesting wireless tidbits ( Ubuntu )

On HP laptops, the module hp_wmi is used for processing hotkeys related to the wireless.

I was running into an issue where after shutting down my laptop's wireless with the button, it refused to start back up again, with the same button.

So after a bit of research, I found these things to be useful .

Command 1: rfkill
Very Important tool for wireless. 
     - rfkill list - Lists the states of the various wireless devices.
     - rfkill (un)block <index> - blocks or unblocks the wireless device listed at the index.

Command 2: lsmod | grep <snipit of module name >
Looks through the modules installed in the kernal for the name. Useful in this case to see if hp_wmi is installed.

Command 3: sudo modprobe <module>
Activates module in the kernel.

Command 4: sudo modprobe -r <module>
Removes module in the kernel.

So, as soon as I added hp_wmi using modprobe, it started working again.

Also, to make sure it is run at boot, add hp_wmi to a new line of /etc/modules using your favourite super user powered text editor.

Monday, November 15, 2010

Firewall script snippets

#This is going to drop packets that claim to be from the loopback interface but
#are coming in on a physical network interface. These packets are clearly
#spoofed and should be dropped.
#$IPTABLES -A INPUT --in-interface ! lo --source 127.0.0.0/8 -j DROP
#above is the version that yields an error, use the one below instead
$IPTABLES -A INPUT --in-interface $EXTIF --source 127.0.0.0/8 -j DROP

#This line prevents the smurf attack, which depends on flooding a
#network with ping requests. We can prevent this attack by only allowing
#one ping request per second.
$IPTABLES -A INPUT -p icmp -m icmp -m limit --limit 1/second -j ACCEPT


#We also want to drop any packets that have TCP flags that don't make
#any sense. To really understand these lines, you are going to need to
#understand the TCP protocol and that is beyond the scope of this video.
#All you really need to know is that the TCP protocol allows different
#flags to be set, and we are going to drop packets where the flags
#contradict each other or otherwise don't make logical sense.

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags FIN,ACK FIN -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags ACK,URG URG -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j DROP

$IPTABLES -t filter -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP

Sunday, November 14, 2010

Adding Scripts to run at Boot ( Linux )

Running a script at boot is sometimes very important.  You, the user, can decide which programs run on log in to your account via the "start up applications" system menu. 

However this doesn't do system wide scripts.  A good example of one that would be an important system wide script is a firewall script.

To get this to run as linux boots up, copy the script to /etc/init.d/.

Then, run the command
update-rc.d <script file > defaults