Scripted Country Geolocations Using OS X’s Built-In ip2cc

Recently I was working on a project where we were isolating IP addresses by country. In the process, I found an easy little tool built right into OS X called ip2cc. Using ip2cc, you can lookup what country an IP is in. To do so, simply run ip2cc followed by a name or ip address. For example, to lookup you might run: ip2cc Or to lookup Much Music, you might run: ip2cc The output would be: IP::Country modules (v2.28) Copyright (c) 2002-13 Nigel Wetters Gourlay Database updated Wed May 15 15:29:48 2013 Name: Address: Country: CA (Canada) You can just get the country line: ip2cc | grep Country: To just get the country code: ip2cc | grep Country: | awk '{ print $2 }' Finally, ip2cc is located at /usr/bin/ip2cc so we’ll complicate things just a tad by replacing the hostname with the current IP (note that private IPs can’t be looked up, so this would only work if you’re rocking on a wan ip or feeding it what a curl from a service like whatismyip brings back): ip2cc `ipconfig getifaddr en0` | grep Country: | awk '{ print $2 }'

Opposite Day: Reversing Lines In Files

The other day, my daughter said “it’s opposite day” when it was time to do a little homework, trying to get out of it! Which reminded me of a funny little command line tool called rev. Rev reads a file and reverses all the lines. So let’s touch a file called rev ~/Desktop/revtest and then populate it with the following lines: 123 321 123 Now run rev followed by the file name: rev ~/Desktop/revtest Now cat it: cat !$ Now rev it again: rev !$ You go go forward and back at will for fun, much more fun than homework… Enjoy!

Core Dumps in Mac OS X

Every now and then, OS X has to drop some kids off at the pool. Usually it’s some developer that didn’t build a sanity check for every-single-possible-flippin’-thing-you-might-think-to-do-to-his/her-poor-flippin’-app-OMGYFI! And then, suddenly, out of nowhere, you get crap all over the system. Actually, as expected, Apple’s dumps are pretty well sequestered in the /cores directory. Each core file has a number appended behind it. For example, core.9901. When applications crash, they can save a lot of information about the state when they crashed into these files. For example, I have seen  cached passwords in there… To disable core dumps, add the following line to /etc/sysctl.conf: kern.coredump=0 After a restart core dumps will be disabled. You can also set the coredump setting to 0 to disable it live, using the sysctl command, but it will revert back to 1 at the next reboot: sudo sysctl -w kern.coredump=0 Existing core files are removed using the following command: sudo rm -f /cores/* As core files actually serve a purpose, if an application or the system needs some good troubleshooting-foo, re-enable: sudo sysctl -w kern.coredump=1

Symbolic Link vs Alias

A symbolic link is *not* an alias. A symlink (symbolic link) is in the filesystem so all of the layers of the OS can use symlinks. This includes Carbon, Cocoa, Java, and BSD apps. Alias files are Finder-specific concept. Aliases are not used by the rest of the system. Only the Finder deals with aliases. At the Finder level, aliases and symlinks are similar, but symlinks are far more versatile and used in pretty much every flavor of *nix.