473,503 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 3378

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

Similar topics

1
2033
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
2118
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
2100
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
7204
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
7091
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
7282
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
5586
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
4680
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...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.