Monthly Archive for January, 2009

Find an IP address and tons more in Apache logs with Regular Expression and egrep or grep

I wanted to look through my apache logs and pull out a list of IPs. I wanted to use SSH. I am kinda new to regular expression so it took me 3 tries, but I ended up with this big string of junk to do just that. The -o tag makes it only spit out the IP out of each line while the rest will grab any grouping of numbers separated by 4 periods.

egrep -o ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+

the ^ means beginning of line
[0-9] means any number, 1-10
the + means one or more times in a row
the \ means literally interpret the next character

Then i went a step further and wanted to figure out how many UNIQUE users I had visiting for a particular access log.

cat access.log.0 | egrep -o ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ | sort | uniq -c | sort

note: uniq -u -c seemed to leave duplicates… this worked a little slower, but reliably. I’m probably doing something wrong there.

Okay so now the NEXT step! Lets do a reverse lookup on all those IPs to see some hostnames… why not?!?!?! We’re going crazy here.

for ip in `cat access.log.0 | egrep -o ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ | sort | uniq`; do dig -x $ip | grep PTR | egrep -v ^\; >> hosts.txt; done

The for loop above lists all the reverse PTR records for every unique IP in the entire log file. The output is dumped to hosts.txt. I had to do a little hackery and exclude lines starting with ; because i was getting duplicates, but it worked. Phew, that command took awhile. I hope my shared web host doesn’t mind about 4,000 reverse DNS lookups.

So what will he do next?! Well, to avoid running that big command ever again, we dumped the results to hosts.txt. Try doing a grep on that for .gov, or something like that. That would look like this:

grep \.gov\.$ hosts.txt

That should roughly be all the government addresses that hit my web server.
Then you could count how many that is, too:

grep \.gov\.$ hosts.txt | uniq | wc -l

Nice!

Some dell drivers not properly displayed when searching by service tag.

This comptuer does not meet the minimum requirements for installing the software.

This comptuer does not meet the minimum requirements for installing the software.

Long story short, when you search some Dell computers by their service tag, the correct drivers for that sysetm are not always displayed. When downloading drivers via the service tag I was faced with the error seen above: “This comptuer does not meet the minimum requirements for installing the software.”. Searching by service tag is supposed to only display drivers that work for that specific system, as shipped. However, I had this problem on two seperate C521s. The real driver is on the website, but you’ll have to browse by product name and look at the full list of options to find your driver. this problem could be happening on other systems, but so far I’ve only seen it on a Dell C521

Start downloading .torrent files from anywhere with uTorrent and Dropbox

Ever been away from your home computer and thought: “Man, I would like to start that torrent download now so it’ll be done when I get home later.” ? Well, now there’s a way to drop .torrent files into a location on your computer and have it automatically begin downloading where you have utorrent running. uTorrent watches a directory for torrents and dropbox gets them there. I give my friend Jake credit for this one… this came naturally to him when he installed Dropbox.

The process is two fold. First, install and register a Dropbox account from www.getdropbox.com. Dropbox lets you sync up to 2G of files for free across all of your computers. It reminds me somewhat of an automated version control system that all your computers are constantly watching for changes. Just change a file on any of your computers and the change is synced across all of them.

Once you have installed Dropbox and registered for an account, create a folder named ‘Torrents to download’ within the ‘Dropbox’ folder you now have in ‘My Documents’. Repeat the sign-up and download process on the computer you want to host the torrent downloads and link it to the same account. Try putting files in from one computer and watching them pop out on the other end. You can also use the online web interface by logging in at www.getdropbox.com to upload a file into your Dropbox… or pull one out.

Install utorrent from the official site here; then open the preferences screen (options -> preferences). Choose directories from the left side menu and then check the box labeled ‘automatically load .torrents from’. Specify your Dropbox folder you created earlier: ‘Torrents to download’. Click the ‘delete loaded .torrents’ too if you like. It’s a neat feature.

Now, go to any computer where you have dropbox and just plop a torrent file in there. You’ll notice that if you checked the ‘delete loaded .torrents’ option it will go away moments later. Your other utorrent computer will catch the change, load the file into utorrent then delete it… that well then be synced back to you and the file will be removed right before your eyes. I strongly encourage looking at some of the other options within utorrent, too.

It’s true utorrent does have a web interface, but that would require you to open up firewall ports – ew! This method bypasses all that madness and your torrent files start instantly. I use it!

Boot UBCD (Ultimate Boot CD) from your Android phone (T-Mobile G1)

I was thinking about neat things to do with all the space on my 4Gb Micro SD card one day when I realized… I could put a bootable OS on there! The first one that came to mind was my personal favorite utility CD: UBCD. Ultimate Boot CD lets you view drive contents and tons tons more. Any computer that can boot off a USB device is yours to use. Since the G1 can use up to 16Gb SDHC memory cards, there’s plenty of room to install and boot… anything!

I did some quick Googling and found this helpful site that explains just how to boot UBCD off of a thumb drive. It’s actually quite easy.

Step 1:
Get a microSD or SDHC card that is at least 500Mb and install it in your G1. For newbies: the slot flips open just below the green call button, you’ll have to put the keyboard up to see it.

Step 2:
Get a USB cable and hook your G1 into your computer. Slide the notification pane down and select the item named ‘USB Connected’ then choose ‘Mount’ from the popup options.

Step 3:
Download and install UBCDfix2.exe which I have re-hosted on this blog here. If you don’t trust me, an alternate location is listed on the pendrivelinux.com post. Run the EXE and extract the files to a folder named UBCD on your desktop.

Step 4:
Download the most current UBCD image. Here’s a link. Move it into the root of the UBCD folder you created on your desktop and put the UBCDfix2 files in.

Step 5:
From the UBCD folder on your desktop, click fixubcd2.bat and follow the onscreen instructions.

DONE! You should now be able to reboot into your thumb drive. Be sure your motherboard both supports booting from a USB device and has the priority for that set above the normal hard drive. On a newer Dell, you can hit F12 to directly choose what to boot off of. Not only can you still save data to your thumbdrive from your G1 like usual, but you can get to all the stuff on your G1 via the UBCD you boot off of too.

Boot UBCD from your G1 Phone

Boot UBCD from your G1 Phone

Oh yeah, and for all you guys who think the USB headset was stupid on the G1, consider USB headsets a blessing. Your headset can now talk back to the phone. Did you know you can press the button on the headset to switch songs or start playing music without even unlocking or touching your phone? You can also do all this over Bluetooth 2.0 once Cupcake releases this month too. I picked up a Voyager 855 just for that.

EDIT: Though it’s possible to install UBCD4Win onto your G1, I do not have the steps outlined here yet. I will return in the future and post them. UBCD4Win lets you browse the web with firefox, use a full featured GUI and run tons of programs.

Enjoy! Subscribe and comment.