473,382 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

IP adrss and networks in Postgresql

I need to do some "IP address based guessing" what should happen inside my application.Ie if given ip adress is from network 'foo' do something, if given IP adrss is from network 'bar', do something else.
So I need to set up table with network definitions like this :

create table network_rules (network inet, rules text )

let's assume that I fill it with the definition of network or hosts.For example like this

10.0.0.1/24
192.168.0.1/24
192.168.0.128/25
192.168.0.200/32 (single host)

Now i have given *some* ip adress and I need to create a SELECT that return all networks with given ip adress belongs to , ordered by netmask, most accurate (ie more bits in netmask set ) first.

Is it possible with postgres and inet datatype ? I have no idea how to do that. Please help.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #1
1 2591
"NTPT" <nt**@centrum.cz> writes:
I need to do some "IP address based guessing" what should happen inside my application.Ie if given ip adress is from network 'foo' do something, if given IP adrss is from network 'bar', do something else.
So I need to set up table with network definitions like this : create table network_rules (network inet, rules text )
Most likely you want to declare the network column as 'cidr' not 'inet',
so that the datatype will enforce that it's a valid network spec. I
can't imagine any case where you'd want bits set to the right of the
netmask in this table.
Now i have given *some* ip adress and I need to create a SELECT that return all networks with given ip adress belongs to , ordered by netmask, most accurate (ie more bits in netmask set ) first. Is it possible with postgres and inet datatype ?


Sure. The contains-or-equals operator selects the rows you want
(network >>= 'target-ip') and you can order by masklen(network).

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Otis Green | last post by:
Vote for or against a new newsgroup proposal. To summarize what you need to do, just send an empty e-mail to postgresql-ballot@netagw.com You will receive a ballot by e-mail. Follow the...
2
by: John Walton | last post by:
Hello, again. I'm back with my instant messenger project. My teacher has assigned us to write our papers, excluding the procedure, results, and conclusion. One of my topics is going to be...
6
by: Tom Kent | last post by:
I have a computer with two network cards (attached to seperate networks) and I am having trouble getting my C# application to send its multicast packets on a specific one. It receives just fine...
1
by: Joe Black | last post by:
Hi all, I'm studing affiliate marketing networks, and I was wondering if anybody knows how Affiliate Service Providers (ASPs)like cj.com or linkshare.com track successful sales on merchant...
0
by: Greg Sabino Mullane | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This is a PGP-signed copy of the checksums for following PostgreSQL versions: 7.4.5 7.4.4 7.3.7
0
by: masterjuan | last post by:
Networks Hacking (hack C:/ drives, severs...)and security holes all on my website & hacking commands and I explain ways of erasing your tracks so you dont get caught doing "bad" things... What do...
3
by: CoreyWhite | last post by:
A friend of mine just was over at my house explaining Neural Networks and I understood it as well as I could. Here is my own explination. A neural network has to first run in a loop 1,000's of...
1
by: satya0674 | last post by:
Hi Everybody , Is any one have the soft copy of the book Developing IP Multicast Networks: The Definitive Guide to Designing and Deploying CISCO IP Multi- cast Networks by Beau...
10
by: iheartvba | last post by:
Hi, I hatve 2 peer to peer networks which I am triying to connect via the Windows XP VPN application. I have achieved the following: 1. Connect to Remote Office 2. Ping all Computer IP...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.