In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to convert IP addresses into integer numbers". In daily operation, I believe that many people have doubts about how to convert IP addresses into integer numbers. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to convert IP addresses into integer numbers". Next, please follow the editor to study!
[conversion principle]: assuming that IP is: w.x.y.z, the formula for calculating the conversion of IP addresses to integer numbers is: intIP = 256256256w + 256256x + 256roomy + z
[interconversion of PHP]: the conversion mode of PHP is relatively simple, it has two built-in functions
Int ip2long (string $ip_address) and string long2ip (string $proper_address)
Can be called directly using ~
[interchange of Asp]: the custom function is as follows
'. -.
'| describtion: convert IP to int numbers |
'| Authors: abandonship (http://jb51.net) |
'~-- ~
Function IP2Num (ByVal strIP)
Dim nIP
Dim nIndex
Dim arrIP
ArrIP = Split (strIP,., 4)
For nIndex = 0 To 3
If Not nIndex = 3 Then
ArrIP (nIndex) = arrIP (nIndex) * (256 ^ (3-nIndex))
End If
NIP = nIP + arrIP (nIndex)
Next
IP2Num = nIP
End Function
'. -.
'| describtion: convert int numbers to IP |
'| Authors: abandonship (http://jb51.net) |
'~-- ~
Function Num2IP (ByVal nIP)
Dim strIP
Dim nTemp
Dim nIndex
For nIndex = 3 To 0 Step-1
NTemp = Int (nIP / (256 ^ nIndex))
StrIP = strIP & nTemp & "."
NIP = nIP-(nTemp * (256 ^ nIndex))
Next
StrIP = Left (strIP, Len (strIP)-1)
Num2IP = strIP
End Function
[interchange of MsSQL]: the custom function is as follows
/ *
* convert IP to int numbers |
* Code CreateBy abandonship (http://jb51.net) |
* * /
CREATE FUNCTION [dbo]. [ipToInt] (
@ strIp varchar (15)
) RETURNS bigint
AS
BEGIN
Declare @ nIp bigint
Set @ nIp = 0
Select
@ nIp = @ nIp + LEFT (@ strIp, charindex ('.', @ strIp+'.')-1) * Id
From (
Select Id = cast (1 "256" 256 as bigint)
Union all select 1 "256" 256
Union all select 1x 256
Union all select 1
) as T
Return (@ nIp)
END
/ *
* convert int numbers to IP |
* Code CreateBy abandonship (http://jb51.net) |
* * /
CREATE FUNCTION [dbo]. [intToIP] (
@ nIp bigint
) RETURNS varchar (15)
As
BEGIN
Declare @ strIp varchar (15)
Set @ strIp =''
Select
@ strIp = @ strIp +'.'+ cast (@ nIp/ID as varchar), @ nIp = @ nIp%ID
From (
Select ID = cast (1 "256" 256 as bigint)
Union all select 1 "256" 256
Union all select 1x 256
Union all select 1
) as T
Return (stuff (@ strIp,1,1,''))
END
[conversion of MySQL]: compared with MsSQL, the conversion mode of MySQL is relatively simple. Like PHP, it also has two built-in functions.
IP to integer: select INET_ATON (IP address) and integer to IP: select INET_NTOA (integer value of IP)
Can be called directly using ~
At this point, the study on "how to convert IP addresses into integer numbers" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.