Archive

Posts Tagged ‘Programming’

PHP: Validate an IP Address

March 13th, 2010 Andrew No comments

So you need to check if some string is a valid IP address. You could simply test it against a regular expression:

1
2
3
4
5
6
7
function is_valid_ipv4($ip)
{
    return preg_match('/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'.
        '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'.
        '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'.
        '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/', $ip) !== 0;
}

Regular Expression obtained here

This will actually work for most situations, but it’s lacking in a few ways. Suppose you want to exclude private or reserved IP addresses. Maybe you want to validate IPv6 addresses too; not just IPv4.

Enter PHP’s Data Filtering Extension. It just works, and you don’t have to worry about maintaining (or properly applying) complex regular expressions.

Read more…

tour
  • Share/Bookmark
careers

Google’s Chrome OS – First Impressions

November 20th, 2009 Andrew 3 comments

Yesterday, Google officially announced their new Chrome OS and explained what it will be when it’s released.  They also published the source code to allow developers and other interested parties to take a peek.  I’m one of those “other interested parties.”
Read more…

feed
  • Share/Bookmark
notice

Install Ejabberd 2.0 on Ubuntu Hardy Heron 8.04 LTS – 6 Steps!

November 12th, 2009 Andrew No comments

Problem:

You’ve chosen the most simple, solid Linux server – Ubuntu 8.04 LTS, and you want to run the most simple, solid XMPP server – ejabberd. BUT, the version of ejabberd in Hardy’s repositories is the really old (Sep 03, 2007!) 1.1.4 release.

Solution:

You could of course build ejabberd from source, but that’s not why you chose the “It Just WorksTM” Ubuntu server, is it? Have no fear. A simple and (mostly) painless solution awaits!

Read more…

  • Share/Bookmark
contact

RFC Standard for the transmission of IP datagrams on Avian Carriers

October 28th, 2009 Andrew No comments
Nerd alert: This post contains off-the-charts geek humor. You’ve been warned.

Thanks to my friend who sent me this.

Uber-geeks will recognize “RFC” (yet another TLA) as short for “Request For Comments.” But those with lives normal folks might need an explanation.

The Internet Engineering Task Force (IETF) has created RFC as a standard for documentation of Internet-related subjects. There is an RFC for just about everything, including:

A lot of RFC’s are standards, but the vast majority of them are not. Almost all of them, though, are painfully dry reads. That said, there are some glaring exceptions.

Read more…

search
  • Share/Bookmark
handbook

C# Detect Windows OS Version – Part 2 (WMI)

October 7th, 2009suggest Andrew 2 comments

Recap

In case you missed Part 1, I briefly summarized 4 different strategies for programmatically determining the current Operating System in C#.  The code I posted there utilizes the System.Environment class.  It works great and is sufficient for most uses, but sometimes you want need to know everything about the OS, including the edition (i.e. “XP Pro” vs. “XP Home”).

Summary

For that, Microsoft gives us the lovely Windows Management Instrumentation (WMI) Interface.  You can do a lot of really powerful and interesting things with WMI and WQL, but for this purpose, all we care about is getting some information from it.

Read more…

  • Share/Bookmark