Computing.Net > Forums > Programming > VBScript comparing IP's

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBScript comparing IP's

Reply to Message Icon

Name: smithy14975
Date: November 10, 2008 at 19:10:45 Pacific
OS: XP
CPU/Ram: intell 2 gig
Product: Dell
Comment:

I would like to know if it is possible to compare IP's in a range with VBScript. For example, I know that if a device's IP address in between 172.31.4.1 through 172.31.4.254 it is located in the lower level of our building. I could make a device locater if I could tell a script in a if else statement to look in certain ranges. Only thing is that dots cause it to error out. I need to be able to format an IP from 172.31.4.1 to 172031004001 or maybe it's binary component of 10101100000111110000010000000001 to 10101100000111110000010011111110

How do you make a function to convert these numbers?



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: November 10, 2008 at 20:08:24 Pacific
Reply:

You could convert it to a number, but VBScript doesn't do unsigned numbers, so that's just a bigger headache than most (me) want to deal with. You could also convert it into a string, but why beat around the comparison bush?

'Return: IP1 < IP2 -> -1
' IP1 = IP2 -> 0
' IP1 > IP2 -> 1

Function IPComp(sIP1, sIP2)
Dim i, num1, num2
num1 = Split(sIP1, ".") : num2 = Split(sIP2, ".")
For i = 0 To 3
If CInt(num1(i)) < CInt(num2(i)) Then
IPComp = -1
Exit Function
ElseIf CInt(num1(i)) > CInt(num2(i)) Then
IPComp = 1
Exit Function
End If
Next 'i
End Function


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBScript comparing IP's

Ping 6 ip's and e-mail me if fail www.computing.net/answers/programming/ping-6-ips-and-email-me-if-fail/15447.html

VBScript IP Address within range www.computing.net/answers/programming/vbscript-ip-address-within-range/14735.html

Find then compare two #'s in batch www.computing.net/answers/programming/find-then-compare-two-s-in-batch/17217.html