How to identify if the access is internal or external?

Asked

Viewed 342 times

0

I have an application in Asp.mvc that has 3 (three) types of access, 2 internal and 1 external. Internal access is done by LDAP and external access by a user table.

No entanto o usuário externo também pode está na rede interna.(aqui é a xarada)

How to identify this access? Because the application consumes internal services that use different IP for external access. Hence I need to know what type of access to put the right IP for the consumption of the service.

Ex:

usuario de acesso interno com DAP quer consultar um pdf (ipInterno:56644/consulta)

Another access, but it is the same IP service, because it is in the internal network

Usuario de acesso externo mas na rede interna quer consultar um pdf (ipInterno:56644/consulta)

Other

Usuario de acesso externo fora da rede interna quer consultar um pdf (ipExterno:56344/consulta)

1 answer

1


Since your company’s IP is fixed, you can check this way, do the IP check, if it’s corporate make a call, if it’s not, make another call.

The below follows two ways to check the external IP

First by WebClient consuming third party service

string meuIpExternoDownload = new WebClient().DownloadString("https://api.ipify.org");

Console.WriteLine($"Meu IP por download: {meuIpExternoDownload}");

The second would be downloading the library IpPublicKnowledge for nuget - (Install-Package IpPublicKnowledge)

var ip = IPK.GetMyPublicIp();
var IPinfo = IPK.GetIpInfo(ip);

Console.WriteLine($"Meu IP por IpPublicKnowledge: {IPinfo.IP}");

Tip: If you choose to do so, save the External IP in some configuration file(web.config), so if the fixed IP, for some reason change, you will need to change only there.

  • 1

    I will adapt to my code, if it works I mark the answer. Thank you since

  • this service returns me 189.16.19.50 when in fact my network starts with 10.21

  • This IP(10.21) is from your machine and is internal, what begins with 189[...] is the external IP, from a look here What is an IP. The internal IP is not safe to do this check, because the internal IP may be the same on the home computer as on the work one. In this website you can see your external IP.

  • The Intiuto is to know whether access comes from outside the company or from within. For this return, I will always have access set to external when actually I am accessing from within the company network.

  • If your system is published on the Internet you will always have an external IP accessing it. Whether it is an employee’s home or company’s home. If your company’s IP is fixed you can see if it’s accessing from within the company or from outside. Because in the case of an access from outside the company the External IP will be another. However, the external IP of the company would have to be fixed.

  • the company’s IP is fixed... That would be just what I need. See if it accesses from within the company or from outside.

  • So, the 189 IP[...] you returned is your company’s fixed external IP. Example, at the moment my internal IP is 10.20[...], already the external is 200.155[...], in my case I would do if(meuIpExterno == '200.155[...]') //Faz alguma coisa

  • If you wish, we can move this conversation to chat, there I can try to explain better..

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.