Data types for IP address.

Started by Gaini Rajeshwarabout 15 years ago10 messagesgeneral
Jump to latest
#1Gaini Rajeshwar
raja.rajeshwar2006@gmail.com

Hi All,

I wanted to store ip addresses in table. I wanted to support the following 3
types of ip addresses.

*1. Wildcard format :* 1.2.3.*
*
*
*2. CIDR format :* 1.2.3/24 OR 1.2.3.4/255.255.255.0
*
*
*3. Start-End IP format :* 1.2.3.0-1.2.3.255

I had a look at CIDR datatype and inet datatype but it seems they support
only partial of the above requirements. Any suggestions on what datatype is
useful for this purpose?

Thanks

#2Sim Zacks
sim@compulab.co.il
In reply to: Gaini Rajeshwar (#1)
Re: Data types for IP address.

a regular varchar or text field.

On 02/23/2011 02:09 PM, Gaini Rajeshwar wrote:

Show quoted text

Hi All,

I wanted to store ip addresses in table. I wanted to support the
following 3 types of ip addresses.

|*1. Wildcard format :* 1.2.3.*
*
*|
|*2. CIDR format :* 1.2.3/24 OR 1.2.3.4/255.255.255.0
<http://1.2.3.4/255.255.255.0&gt;
*
*|
|*3. Start-End IP format :* 1.2.3.0-1.2.3.255

|
|
|
I had a look at CIDR datatype and inet datatype but it seems they
support only partial of the above requirements. Any suggestions on
what datatype is useful for this purpose?

Thanks

#3Stephane Bortzmeyer
bortzmeyer@nic.fr
In reply to: Sim Zacks (#2)
Re: Data types for IP address.

On Wed, Feb 23, 2011 at 02:30:18PM +0200,
Sim Zacks <sim@compulab.co.il> wrote
a message of 97 lines which said:

a regular varchar or text field.

Very bad idea since they don't support canonicalization (2001:db8::1
== 2001:db8:0:0:0:0:0:1) or masking (set_masklen(address, 20)).

#4Stephane Bortzmeyer
bortzmeyer@nic.fr
In reply to: Gaini Rajeshwar (#1)
Re: Data types for IP address.

On Wed, Feb 23, 2011 at 05:39:26PM +0530,
Gaini Rajeshwar <raja.rajeshwar2006@gmail.com> wrote
a message of 52 lines which said:

I wanted to store ip addresses in table. I wanted to support the following 3
types of ip addresses.

*1. Wildcard format :* 1.2.3.*
*
*
*2. CIDR format :* 1.2.3/24 OR 1.2.3.4/255.255.255.0

What is the difference between 1.2.3.* and 1.2.3.0/24? For me, it is
exactly the same. If you just want the ability to INPUT 1.2.3.*, just
write a small conversion routine in your favorite programming
language.

*3. Start-End IP format :* 1.2.3.0-1.2.3.255

You don't even need to program the conversion, it is already done:

% netmask 1.2.3.0:1.2.3.255
1.2.3.0/24

#5John R Pierce
pierce@hogranch.com
In reply to: Stephane Bortzmeyer (#4)
Re: Data types for IP address.

On 02/23/11 4:44 AM, Stephane Bortzmeyer wrote:

*3. Start-End IP format :* 1.2.3.0-1.2.3.255

You don't even need to program the conversion, it is already done:

% netmask 1.2.3.0:1.2.3.255
1.2.3.0/24

yes, but what about 10.1.2.57-10.1.2.123 ? presumably valid in his
range system, and certainly NOT a valid CIDR range.

#6Michael Glaesemann
grzm@seespotcode.net
In reply to: John R Pierce (#5)
Re: Data types for IP address.

On Feb 23, 2011, at 13:49, John R Pierce wrote:

On 02/23/11 4:44 AM, Stephane Bortzmeyer wrote:

*3. Start-End IP format :* 1.2.3.0-1.2.3.255

You don't even need to program the conversion, it is already done:

% netmask 1.2.3.0:1.2.3.255
1.2.3.0/24

yes, but what about 10.1.2.57-10.1.2.123 ? presumably valid in his range system, and certainly NOT a valid CIDR range.

If it hasn't been mentioned already, take a look at ip4r. <http://pgfoundry.org/projects/ip4r/&gt;

Michael Glaesemann
grzm seespotcode net

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: John R Pierce (#5)
Re: Data types for IP address.

John R Pierce <pierce@hogranch.com> writes:

On 02/23/11 4:44 AM, Stephane Bortzmeyer wrote:
*3. Start-End IP format :* 1.2.3.0-1.2.3.255

You don't even need to program the conversion, it is already done:

% netmask 1.2.3.0:1.2.3.255
1.2.3.0/24

yes, but what about 10.1.2.57-10.1.2.123 ? presumably valid in his
range system, and certainly NOT a valid CIDR range.

The question is does he actually have a use-case for address ranges that
don't correspond to legal CIDR ranges, but do nonetheless have an
identifiable lower boundary, upper boundary, and no holes? And if so,
what is it? The whole thing looked to me like somebody inventing
requirements with little or no study of what they really needed.

regards, tom lane

#8John R Pierce
pierce@hogranch.com
In reply to: Tom Lane (#7)
Re: Data types for IP address.

On 02/23/11 1:33 PM, Tom Lane wrote:

The question is does he actually have a use-case for address ranges that
don't correspond to legal CIDR ranges, but do nonetheless have an
identifiable lower boundary, upper boundary, and no holes? And if so,
what is it? The whole thing looked to me like somebody inventing
requirements with little or no study of what they really needed.

indeed. i had to poke around the ban tables of MyBB the other day (a
php bbs that works reasonably well* on postgresql), and they were
storing IP bans as strings like 1.2.*.* or 1.2.3.4-1.2.4.5 or whatever.
UGH.

* it works mostly on PG but has some bugs around the edges of the admin
stuff. the worst ones I've found fixes for and submitted back to the
mybb team, but mostly I'm too lazy and just work around them

#9Gaini Rajeshwar
raja.rajeshwar2006@gmail.com
In reply to: Tom Lane (#7)
Re: Data types for IP address.

On Thu, Feb 24, 2011 at 3:03 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

John R Pierce <pierce@hogranch.com> writes:

On 02/23/11 4:44 AM, Stephane Bortzmeyer wrote:
*3. Start-End IP format :* 1.2.3.0-1.2.3.255

You don't even need to program the conversion, it is already done:

% netmask 1.2.3.0:1.2.3.255
1.2.3.0/24

yes, but what about 10.1.2.57-10.1.2.123 ? presumably valid in his
range system, and certainly NOT a valid CIDR range.

The question is does he actually have a use-case for address ranges that
don't correspond to legal CIDR ranges, but do nonetheless have an
identifiable lower boundary, upper boundary, and no holes? And if so,
what is it? The whole thing looked to me like somebody inventing
requirements with little or no study of what they really needed.

I have customers who wanted to access application from different
locations without using login credentials every time. So they wanted to
register their ip addresses and have automated authentication for them. As
i don't know how their ip addresses definitely going to be, i am assuming
that they might have a ip address rage that is not a valid CIDR.

Show quoted text

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#10Gaini Rajeshwar
raja.rajeshwar2006@gmail.com
In reply to: Michael Glaesemann (#6)
Re: Data types for IP address.

On Thu, Feb 24, 2011 at 1:10 AM, Michael Glaesemann <grzm@seespotcode.net>wrote:

On Feb 23, 2011, at 13:49, John R Pierce wrote:

On 02/23/11 4:44 AM, Stephane Bortzmeyer wrote:

*3. Start-End IP format :* 1.2.3.0-1.2.3.255

You don't even need to program the conversion, it is already done:

% netmask 1.2.3.0:1.2.3.255
1.2.3.0/24

yes, but what about 10.1.2.57-10.1.2.123 ? presumably valid in his

range system, and certainly NOT a valid CIDR range.

If it hasn't been mentioned already, take a look at ip4r. <
http://pgfoundry.org/projects/ip4r/&gt;

I will look into it. May i know how to use this data type? It is not
available with postgreSQL 8.4 right?
I guess i have to download and integrate into postgreSQL, any suggestions on
how to do?

Show quoted text

Michael Glaesemann
grzm seespotcode net

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general