473,692 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #1
1 2636
"NTPT" <nt**@centrum.c z> 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
2176
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 instructions and vote. _______________________________________________________________________ FIRST CALL FOR VOTES (of 2)
2
1187
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 networks. Does anyone know a list of words relating to networking/networks that I should know for this project? Not the definitions, but just the words; I can look up the definitions on webopedia. It would be appreciated. Thanks! -John
6
5638
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 (I'm assuming because its listening to both networks), but it seems like it just picks the default to send over. I have implemented the MulticastOption(RemoteIP, LocalIP), but it doesn't seem to be changing the interface it sends over. Here's...
1
1477
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 websites. As far as I know the algorithm should be: 1) The affiliate publishes a link with his ID and the Merchant ID in his website (ie. http://www.cj.com/redirect.xxx?id=12345&merch_id=54321) 2) The visitor clicks on the link with the intention to...
0
1659
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
3779
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 you think? check out my website its about hacking networks and step by step guides of how to do it all. Any suggestions on information or anything you think would be interesting to write about please tell me. Also what do you think of the...
3
2937
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 times given it's input and output. It then naturally learns the simplest algorithm to generate that input and output, using a networked matrix of numbers that are run through a filter, and compared to the input. The algorithm to train a neural...
1
3259
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 Williamson if so plz plz frwd that to me
10
8279
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 Addresses in remote office 3. Use Terminal Services (Remote Desktop) on the Server computer- please note the server is also running windows XP. I would like to achieve the following but have been unsuccessfull and am confused on what I am doing wrong. ...
0
8608
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8963
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8806
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5820
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4324
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2241
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1959
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.