Prolog CIDR IP Matching

16 views
Skip to first unread message

Felix Schmidt

unread,
May 10, 2017, 9:54:34 AM5/10/17
to SWI-Prolog
Hi,

I'm new to prolog. I have a questions for you experts. I was using google already, but haven't found a solution yet.

I want to do CIDR matching in Prolog.

Basically what I would like to do is the following:


ip(10.0.0.1) -> How can I check that this IP is a match based on the CIDR?
ip(10.0.1.1) -> This IP would be no match.

Thanks
- felix

Jan Wielemaker

unread,
May 10, 2017, 11:23:02 AM5/10/17
to Felix Schmidt, SWI-Prolog
On 05/10/2017 03:54 PM, Felix Schmidt wrote:
> Hi,
>
> I'm new to prolog. I have a questions for you experts. I was using
> google already, but haven't found a solution yet.

This isn't really the Prolog thingy as it is mostly bit manipulation,
but it can (of course) be done. See

http://swish.swi-prolog.org/p/cidr.pl

Enjoy --- Jan

>
> I want to do CIDR matching in Prolog.
>
> Basically what I would like to do is the following:
>
> cidr(10.0.0.0/24)
>
> ip(10.0.0.1) -> How can I check that this IP is a match based on the CIDR?
> ip(10.0.1.1) -> This IP would be no match.
>
> Thanks
> - felix
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages