Re: Casting hexadecimal IPs to readable content - Mailing list pgsql-general

From Harald Armin Massa
Subject Re: Casting hexadecimal IPs to readable content
Date
Msg-id 7be3f35d0711220835l7305c303k10c450ef4fb491de@mail.gmail.com
Whole thread Raw
In response to Casting hexadecimal IPs to readable content  (Jean-Michel Pouré <jm@poure.com>)
List 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@poure.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!

pgsql-general by date:

Previous
From: Jean-Michel Pouré
Date:
Subject: Casting hexadecimal IPs to readable content
Next
From: "Sergey Konoplev"
Date:
Subject: Re: Dynamic expressions set in "order by" clause