473,840 Members | 1,670 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.LongIPFucti on([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("Pleas e 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(TestI P,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 3395

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

Similar topics

1
2057
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: http://members.iinet.net.au/~allenbrowne/AppInventory.html to suit a few ideas of my own. I have thought that I might "simplify" Allen's table structure a little,
6
2144
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 "string" in google comp.lang.c archives.Hope this helps.Hope I am not bothering any one. am I? =================================Start=========================== subject: Return to Start of Line? Question: I'd like printf, the next printf, to return...
0
2129
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 program runs... and when i hit start button it calls Q_SendHeader function. Form1_Load(..................... Q_KDSPort = &H8000&
0
9699
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10301
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9444
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7839
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5685
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4078
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.