Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Compare IP Address to range of IP Addresses

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,38040
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Compare IP Address to range of IP Addresses
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Compare IP Address to range of IP Addresses - 9/24/2006 12:48:19 AM   
  ldmak90

 

Posts: 5
Score: 0
Joined: 9/24/2006
Status: offline
Hello all... I'm new here and new to scripting as well.  I know enough to hurt myself but still not enough to hurt anyone else.  Anyway, here's my question and I hope I explain it right.

How can I determine if an IP Address is within a certain range of IP Addresses in a VBScript?

If I know a range like 192.168.10.1 - 192.168.10.50
Can I grab an IP Address using VBscript, assign it to a variable and then perform some actions if that IP Address falls within that range?

Problem I am having is that I get "expected then" because when I assign an IP Address to a variable it doesn't like anything passed the first decimal point (second octet of the IP). So, IF strIPAddress >= 192.168.10.1 And strIPAddress <= 192.168.10.50 THEN do some stuff here... isn't working... gives me the ' expected THEN ' error.

What am I missing ?? Any help would be greatly appreciated.

Thanks very much,

LD
 
 
Post #: 1
 
 RE: Compare IP Address to range of IP Addresses - 9/24/2006 1:03:37 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline


The syntax for the IF statement is:


      

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to ldmak90)
 
 
Post #: 2
 
 RE: Compare IP Address to range of IP Addresses - 9/24/2006 1:33:06 AM   
  ldmak90

 

Posts: 5
Score: 0
Joined: 9/24/2006
Status: offline
Right... I have the syntax... however, when I use that I am getting the 'expected Then' error.
This is because vbscript doesn't like anything passed the first decimal point in the IP Address value. 

LD

(in reply to Snipah)
 
 
Post #: 3
 
 RE: Compare IP Address to range of IP Addresses - 9/24/2006 3:13:43 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Do a Split() on the IP address and use varIP(3) to compare ranges...

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to ldmak90)
 
 
Post #: 4
 
 RE: Compare IP Address to range of IP Addresses - 9/24/2006 3:27:53 AM   
  ldmak90

 

Posts: 5
Score: 0
Joined: 9/24/2006
Status: offline
These functions are a bit more advanced than what I'm currently capable of... but I appreciate your help.
I will look into what you mentioned and see if I can piece it together.

thanks again,

LD

(in reply to Snipah)
 
 
Post #: 5
 
 RE: Compare IP Address to range of IP Addresses - 9/24/2006 4:09:33 AM   
  ldmak90

 

Posts: 5
Score: 0
Joined: 9/24/2006
Status: offline
quote:

ORIGINAL: Snipah

Do a Split() on the IP address and use varIP(3) to compare ranges...


I found information on Split() and this has given me some new ideas and understanding... However, can you explain more about what you mean regarding varIP(3) ?? 

Thanks,

LD

(in reply to Snipah)
 
 
Post #: 6
 
 RE: Compare IP Address to range of IP Addresses - 9/24/2006 5:13:48 AM   
  ldmak90

 

Posts: 5
Score: 0
Joined: 9/24/2006
Status: offline
quote:

ORIGINAL: ldmak90

quote:

ORIGINAL: Snipah

Do a Split() on the IP address and use varIP(3) to compare ranges...


I found information on Split() and this has given me some new ideas and understanding... However, can you explain more about what you mean regarding varIP(3) ?? 

Thanks,

LD


Nevermind Snipah... I got it... just started playing with it and realized I'm pulling elements of an array.

Thanks very much again... it's always fun to actually learn something because the person who helped didn't give too much... but just enough to spark your thinking...

GREATLY appreciated...

LD

(in reply to ldmak90)
 
 
Post #: 7
 
 RE: Compare IP Address to range of IP Addresses - 9/24/2006 9:32:24 PM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
An alternative approach would be use the Dictionary object to hold your IP address range and then check to see if the IP address you are testing exists in the Dictionary.  

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ldmak90)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Compare IP Address to range of IP Addresses Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts