We help IT Professionals succeed at work.

Need help with VB Script that grabs Subnet

DakotaKat
DakotaKat asked
on
I have a script that grabs the subnet of our users internally. I need to modify it so it grabs just the first number, IE 172 in this case. If the users subnet begins with 172 then it will spit out a message.

I have attached my code below, I dont seem to be getting the syntax right.
<%
Dim ip,subB,subC, LocalContentURL, DisplayLocation
ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If ip= "" Then ip = Request.ServerVariables("REMOTE_ADDR")
subC=left(ip,instrrev(ip,".")-1)
subB=left(subB,instrrev(subC,".")-1)

select case subC
	
case "172.16.50"
   
	DisplayLocation =  "Your at Home 172.16.50"
	
case "172"
   
	DisplayLocation =  "Script Update is working"
	

	
case Else
   
	DisplayLocation =  "<BR><B>*** ALERT *** I HAVE NO IDEA WHAT NETWORK YOU ARE ON!</B>"
		
end select
%>

<% 
	response.write DisplayLocation
%>

Open in new window

Comment
Watch Question

I am not sure what you are trying to completely accomplish, but the code below I think will do what you want.
-Bear

<%
Dim ip,subA, subB,subC, LocalContentURL, DisplayLocation
ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If ip= "" Then ip = Request.ServerVariables("REMOTE_ADDR")
subC=left(ip,instrrev(ip,".")-1)
subB=left(subB,instrrev(subC,".")-1)
subA=left(ip,instr(ip,"."-1)

If subc = "172.16.50" Then
	DisplayLocation =  "Your at Home 172.16.50"
ElseIf subA = "172" Then
	DisplayLocation =  "Script Update is working"
Else	
	DisplayLocation =  "<BR><B>*** ALERT *** I HAVE NO IDEA WHAT NETWORK YOU ARE ON!</B>"
End If

%>

<% 
	response.write DisplayLocation
%>

Open in new window