Why are localhost connections blocked by the firewall?

时间秒杀一切 提交于 2019-12-10 13:47:37

问题


When I listen on a port on localhost, Windows will popup a dialogue in which the user must add my program to the list of firewall exceptions. This is annoying, and requires administrator-rights, which the user may not have.

Why does Windows do this for loopback connections (127.0.0.1) and is there some trick to prevent this?


回答1:


The answer was to specify:

IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Loopback, Port);

instead of

IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, Port);

for the listening socket. At first sight this seems to prevent any firewall warnings and doesn't require any rules to be added to the firewall. But I have to do some more extensive testing to be sure this works on all Windows configurations.




回答2:


It does this to prevent people from doing bad things. If a program is accessing something via localhost, it might do things at higher privileges than it might be able to do if it does it via non-localhost.

Example:

  • A localhost administrative port
  • Applications that only listen to localhost to prevent remote access, file indexing services
  • etc.

There is no way to avoid the popup. Otherwise, what would be the use of it? You can, if your program has administrative privileges, add a firewall exception rule, thus preventing this popup.



来源:https://stackoverflow.com/questions/21230691/why-are-localhost-connections-blocked-by-the-firewall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!