473,413 Members | 1,811 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,413 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 3373

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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.