Re: Casting hexadecimal IPs to readable content

From: "Harald Armin Massa" <haraldarminmassa(at)gmail(dot)com>
To: Jean-Michel Pouré <jm(at)poure(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Casting hexadecimal IPs to readable content
Date: 2007-11-22 16:35:43
Message-ID: 7be3f35d0711220835l7305c303k10c450ef4fb491de@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jean-Michel,

to be sure the documentation of that storage would be needed. But my
educated guess is:

select get_byte(decode(substring('52e1fcb6',1,2),'hex'),0)||'.'||
get_byte(decode(substring('52e1fcb6',3,2),'hex'),0)||'.'||
get_byte(decode(substring('52e1fcb6',5,2),'hex'),0)||'.'||
get_byte(decode(substring('52e1fcb6',7,2),'hex'),0)

of course translated to:

select get_byte(decode(substring("columname",1,2),'hex'),0)||'.'||
get_byte(decode(substring("columname",3,2),'hex'),0)||'.'||
get_byte(decode(substring("columname",5,2),'hex'),0)||'.'||
get_byte(decode(substring("columname",7,2),'hex'),0) from yourtable

where "columname" is the name of the column with the IPs.

Best wishes,

Harald

On Nov 22, 2007 5:13 PM, Jean-Michel Pouré <jm(at)poure(dot)com> wrote:

> Dear Friends,
>
> My PhpBB forum with 4000 users was hacked in Switzerland.
>
> Enquirers (not my own idea) proposed that I look for certain IPs in my
> PostgreSQL 8.2 database. The problem is that PhpBB stored IPs as
> strings, which seem to be more or less encoded.
>
> In PhpBB, IPs are stored as Hexa:
> "54dc0636"
> "52e1fcb6"
>
> How to cast these values to readable content?
> Any idea ? This is an important issue for me.
> Thank you for any help.
>
> Kind regards,
> Jean-Michel
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

--
GHUM Harald Massa
persuadere et programmare
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607
fx 01212-5-13695179
-
EuroPython 2008 will take place in Vilnius, Lithuania - Stay tuned!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sergey Konoplev 2007-11-22 17:04:22 Re: Dynamic expressions set in "order by" clause
Previous Message Jean-Michel Pouré 2007-11-22 16:13:22 Casting hexadecimal IPs to readable content