Query on IP Subnet

K

Kathy

I have a field of IP addresses: i.e, 000.000.000.000. I want users to be able
to enter only a subnet and be able to return only those 255 IP addresses.
The first 6 characters are always the same so they will enter the third set
of numbers. I know I can hard code the query for: Like "000.000.125.???" but
I want them to be able to enter the third set of number (125). Any ideas?
 
A

Allen Browne

Kathy, is there any chance that you could use 4 fields of type Number (size
Byte) to store the IP address?

It seems to me that his solves all the problems of subnets and different
classes of IP address. It also avoids the problems where someone forgets to
enter a leading zero, or enters an invalid number (such as 256) in one of
the segments.
 
K

Kathy

I could do that, I guess, altho I'm reluctant. Someone just suggested I use
another field and just add the subnet to that field so we could do a search
on that. Could do an update query to add the subnet to that field and it's
not like the IP's are ever going to change once they're in the system.

Thanks for your help.
 
A

Allen Browne

An IP address literally is 4 bytes.
We usually represent the IP in decimal format, separated by dots.
It is dead easy to create a form with 4 text boxes, using dots in the
attached labels of all but the first, so the entry screen appears as:
IP Address: [ ].[ ].[ ].[ ]
where the square brackets represent the 4 text boxes.

The 4-byte solution is the best match in Access for an IP address, since:
a) Access has no unsigned long integer, and
b) Access does have unsigned bytes, and
c) an IP consists of 4 discrete unsigned bytes, and
d) the 4 bytes are atomic (e.g. you need to separate them for class A, B,
and C addresses.)

As long as you don't need IPv6. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top