为什么本地主机连接被防火墙阻止? [英] Why are localhost connections blocked by the firewall?

查看:178
本文介绍了为什么本地主机连接被防火墙阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在本地主机上的端口上侦听时,Windows将弹出一个对话框,用户必须在其中将我的程序添加到防火墙例外列表中.这很烦人,并且需要用户可能没有的管理员权限.

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.

为什么Windows会对回送连接(127.0.0.1)进行此操作,并且有一些技巧可以防止这种情况发生?

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

推荐答案

答案是指定:

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

代替

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

用于侦听套接字.乍一看,这似乎可以防止任何防火墙警告,并且不需要向防火墙添加任何规则.但是我必须做一些更广泛的测试,以确保它适用于所有Windows配置.

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.

这篇关于为什么本地主机连接被防火墙阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆