Jump to content

Script run based on IP


lyledg
 Share

Recommended Posts

Guys

I am creating a login script but want to run it for certain users based on their IP address.

I know I can use the @IPAddress1 function to get the IP on the machine logging on, but how would I be able to specify a whole subnet...ie: 192.168.9.0\254 to check against?

A Select case would be the most obvious, but I can't see my self doing this for multiple subnet's!!

Any other way that I could do this would be greatly appreciated!

Cheers

:ph34r:

Link to comment
Share on other sites

Hey,

Just a thought. If the IP range is always 192.168.x.x, you may want to use the

$var = @IPAddress1
$var1 = StringTrimLeft ( $var, 8 )

This way you are left with a decimal number that you can use in if statments

if $var1 > 9.254 then exit
endif

Hope it is what you are looking for

CheersNobby

Link to comment
Share on other sites

If it's always a whole subnet you want to run the script for, you should try to get the number of the net (a simple BitAND, maybe it's even stored somewhere in the registry) and check against this number. It will be the same for every computer in a whole subnet.

Link to comment
Share on other sites

I've found that StringSplit works well for evaluating IP addresses. For example, if you want to identify all of the nodes on 192.168.9.0/25, this might work for you:

$octet = StringSplit( @IPAddress1, ".")
;
If $octet[1] = "192" And $octet[2] = "168" And $octet[3] = "9" And $octet[4] >= "1" and $octet[4] <= "126" Then

Hope this is of some use....

Fully automatic, comes in any sizeMakes me wonder what I did before I got synchronized...

Link to comment
Share on other sites

That great advice all around guys, thanks...

What I did in the end was what Nobby suggested to do a StringTrimLeft as well as a StringTrimright to get the third octet results and check against that, as that is all I need to verify as to what subnet the user is logging into, but your suggestion SPTech will work better I think if more octets need to be checked...Either way thanks to you guys I managed to get it working like I need! Cheers!

Link to comment
Share on other sites

wow, looking at this topic, i have a lot to learn lol. whats a subnet how do u make like creat big programs with auto it, so confusing!

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

@Icekirby1, is your only purpose to litter this forum with unuseful and non-helpful comments? If so you have been doing a marvelous job.

@mephy, a subnet explained:

Every computer on a network or on the internet gets a unique number to identify it from the others on that same network.

Those numbers are usually four sets of numbers separated by periods. (192.168.0.32)

Each set of numbers can only go to 255 max.

A subnet only means a different beginning set of numbers (192.168.0.1 is on a different subnet than 192.168.1.1)

See?

Who else would I be?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...