473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SQL 2005 Function to Convert Dotted IPs to Long IP Format?

Does anyone have a sample SQL 2005 function the converts a Dotted IP address to its Long IP equivalent?

Example: 192.168.0.1 converts to 3232235521.
dbo.LongIPFuction([dbo].[Asset].[IPAddress])

Scenario:
I have a computer Asset table that contains the IP address of an asset and another table that contains the min and max ip ranges in the Long IP format for each site in our company.

Before I can join the tables in a view I need to convert the Asset Table’s IP to a Long IP that I can compare to the SiteList table.

I have several other tables that need the conversion that’s why I am thinking a function is the best solution.

I have a VBS script that I use for other outside tools that also checks for invalid IPs.
It would be nice to convert it to a SQL function, minus the input box of course.

I apologize if the format of the question is wrong, this is my first post
Thanks for you help in advance!!

[VBS Script]
IpAddressCheck = False
Do Until IpAddressCheck = True
IPaddress = InputBox("Please Enter a Valid Dotted IP Address (Example: 192.168.0.1)")
If IPaddress = "" Then
WScript.Quit
End If
IpAddressCheck = IsValidIP (IPaddress)
Loop
IP = Split(IPaddress,".")
AnswerData = IP(3) + (IP(2) * 256) + (IP(1) * 256 * 256) + (IP(0) * 256 * 256 * 256)

WScript.Echo AnswerData
WScript.Quit

Function IsValidIP (TestIP)
WScript.Echo TestIP
IsValidIP = False
DotCheck = 0
For c1 = 1 To Len(TestIP)
If InStr(Mid(TestIP,c1,1),".") <> 0 Then DotCheck = DotCheck + 1 End If
Next
If DotCheck = 3 Then
IPT = Split(TestIP,".")
If (Asc(IPT(3)) < 58 And Asc(IPT(3)) > 47) And _
(Asc(IPT(2)) < 58 And Asc(IPT(2)) > 47) And _
(Asc(IPT(1)) < 58 And Asc(IPT(1)) > 47) And _
(Asc(IPT(0)) < 58 And Asc(IPT(0)) > 47) Then
If (IPT(3) < 256 And IPT(3) > -1) And _
(IPT(2) < 256 And IPT(2) > -1) And _
(IPT(1) < 256 And IPT(1) > -1) And _
(IPT(0) < 256 And IPT(0) > -1) Then
IsValidIP = True
End If
End If
End If
End Function
Jun 20 '07 #1
0 3370

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Don Leverton | last post by:
Hi Folks, I'm still in the process of rewriting my Parts Inventory application, and still using good old Access97 to do it. I'm attempting to modify Allen Browne's code from:...
6
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject...
0
by: remya1000 | last post by:
i'm using VB.Net 2005 application program. i'm trying to convert VB6 code to VB.Net 2005. QSockB is DLL file. this is the code i used for VB6. This is code i'm using to create socket, when...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.