S
S
Sergey2016-12-02 12:57:37
MySQL
Sergey, 2016-12-02 12:57:37

How to calculate ip-addresses using only sql?

We have a Mysql database at work. It has the following columns (description - name - field type):
1. Subnet IP address - IpAddr - INT
2. Subnet mask - Mask - INT
3. First subnet host - StartIp - INT
4. Subnet broadcast - EndIp - INT
5 Point Id from another table - IdFilial - INT
Ip addresses are stored as Integer and are converted back and forth by the native command INET_ATON and INET_NTOA.
If you want to find which network the ip address corresponds to, then a request is created containing approximately the following condition

WHERE StartIp < $Ipaddress AND EndIp > $Ipaddress

I have a desire to shorten the table by removing the columns StartIp and EndIp. I can't figure out what kind of calculation should be for such a request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2016-12-02
@Mercury13

IpAddress & Mask = IpAddr
(assuming the IP is guaranteed to be real and you don't have to find out if it's a real address or one of the service ones associated with the network)
Perhaps - I don't know how big the table is - the database is kept in this form for the sake of indexing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question