Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Q-Vara

[Resolvido] Liberar apenas uma faixa de IP

Recommended Posts

Boas pessoal,

é o seguinte, preciso criar uma regra em um site que proíba o acesso de máquinas que estejam fora de um determinado range de IP.

Preciso também criar um IF para o IP interno da empresa também.

O problema é que nunca fiz isso, alguém pode me ajudar?

Obrigado

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tenta utilizar a idéia do tópico que você viu mais cedo.

http://forum.imasters.com.br/index.php...st&p=283647

 

É praticamente a mesma coisa.

 

Você vai precisar do Request.ServerVariables("REMOTE_ADDR") e da função split (para transforma o ip em vetor e ficar mais fácil para comparar).

Compartilhar este post


Link para o post
Compartilhar em outros sites

Minhas faixas de IP são 179.20.205.179 até 181 e 201.142.128.0 até 20.

Será que assim funciona?

 

<%
Function ControlaIP(ip,faixaDe,faixaAte)
	ip = Replace(ip,".","")
	faixaDe = Replace(faixaDe,".","")
	faixaAte = Replace(faixaAte,".","")
	ip = ip
	faixaDe = faixaDe
	faixaAte = faixaAte
	if ip >= faixaDe AND ip <= faixaAte then
 ControlaIP = False
	else
 ControlaIP = True
	end if
End Function

If ControlaIP(Request.ServerVariables("REMOTE_ADDR"),"201.142.128.0","201.142.128.20") then
	response.write Request.ServerVariables("REMOTE_ADDR") & ": IP dentro da faixa!!"
else If ControlaIP(Request.ServerVariables("REMOTE_ADDR"),"179.20.205.179","179.20.205.181") then
	response.write Request.ServerVariables("REMOTE_ADDR") & ": IP dentro da faixa!!"
else
	response.write Request.ServerVariables("REMOTE_ADDR") & ": IP fora da faixa!!"
end if
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Altera a função aí e testa novamente. Vocè inverteu o true e false.

<%
Function ControlaIP(ip,faixaDe,faixaAte)
	ip = Replace(ip,".","")
	faixaDe = Replace(faixaDe,".","")
	faixaAte = Replace(faixaAte,".","")

	if (cdbl(ip) >= cdbl(faixaDe)) AND (cdbl(ip) <= cdbl(faixaAte)) then
		ControlaIP = True
	else
		ControlaIP = False
	end if
End Function
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

RESOLVIDO

<%
Function ControlaIP(ip,faixaDe,faixaAte)
	ip = Replace(ip,".","")
	faixaDe = Replace(faixaDe,".","")
	faixaAte = Replace(faixaAte,".","")

	if (cdbl(ip) >= cdbl(faixaDe)) AND (cdbl(ip) <= cdbl(faixaAte)) then
		ControlaIP = True
	else
		ControlaIP = False
	end if
End Function

If ControlaIP(Request.ServerVariables("REMOTE_ADDR"),"200.142.128.0","200.142.128.20") then
	response.write Request.ServerVariables("REMOTE_ADDR") & ": IP dentro da faixa!!"
elseif ControlaIP(Request.ServerVariables("REMOTE_ADDR"),"189.20.205.179","189.20.205.181") then
	response.write Request.ServerVariables("REMOTE_ADDR") & ": IP dentro da faixa!!"
else
	response.write Request.ServerVariables("REMOTE_ADDR") & ": IP fora da faixa!!"
end if
%>

Obrigado hargon!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.