为什么浏览器会屏蔽某些端口? [英] Why do browsers block some ports?

查看:90
本文介绍了为什么浏览器会屏蔽某些端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩 websockets,看起来,我测试过的所有支持本机 websocket 的浏览器(Safari、Chrome)都会阻止一些端口.如果我尝试通过端口 80 连接到我的服务器,则一切正常.如果我尝试其他端口,如 81、82 或 1000,连接会过早关闭,因为另一端没有任何东西.这是预期的行为,而且效果很好.

I'm playing around with websockets and it appears, that all browsers with native websocket support I tested with (Safari, Chrome) block some ports. If I try to connect to my server over port 80, everyting works fine. If I try other ports, like 81, 82 or 1000, the connection is prematurely closed because there's nothing on the other end. That's the expected behaviour and it works beautifully.

但是,对于某些端口(例如 20、37 或 79),Chrome 开发人员控制台只是说 WebSocket 端口 79 被阻止 但我的 JS 代码没有收到任何有关此的信息(甚至没有某种超时).Safari 比较冗长,注释 SECURITY_ERR: DOM Exception 18: An试图突破用户代理的安全策略.

However, with some ports (such as 20, 37 or 79), the Chrome developer console simply says WebSocket port 79 blocked but my JS code doesn't receive any information about this (not even some sort of timeout). Safari is a little more verbose and comments SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.

所以我的问题是:

如何可靠地检测端口是否被阻止?
我是否必须设置超时并手动检查?这似乎不是最明智的方法,尽管它可能是跨浏览器执行此操作的唯一方法.

How can I reliably detect that a port is blocked?
Do I have to set a timeout and check that manually? That doesn't seem to be the smartest way to go about it, although it might be the only way to do it cross-browser.

在哪里可以找到被阻止端口的列表?
不幸的是,我的 Google 搜索没有找到任何有用的信息.

Where can I find a list of the blocked ports?
My Google search didn't turn up anything useful, unfortunately.

为什么首先要阻止这些端口?

提前致谢!

推荐答案

好的,我找到了答案.有时,您只是只见树木不见森林.

Okay, I found the answer. Sometimes you just don't see the forest for the trees.

首先,处理阻塞端口的情况是微不足道的.一个简单的 try/catch 就可以解决问题.我只是对 Chrome 显示该异常的方式感到困惑,并没有立即识别出它(我通常使用 Firefox).

First off, handling cases of blocked ports is trivial. A simple try/catch does the trick. I was simply confused by the way Chrome displayed that exception and didn't recognize it as such right away (I usually use Firefox).

其次,WebSockets API 规范明确指出

如果端口是用户代理配置为阻止访问的端口,则抛出 SECURITY_ERR 异常.(用户代理通常会阻止对 SMTP 等知名端口的访问.)

If port is a port to which the user agent is configured to block access, then throw a SECURITY_ERR exception. (User agents typically block access to well-known ports like SMTP.)

究竟是什么端口似乎取决于浏览器的 Websocket 实现.我的测试表明 Chrome 和 Safari 阻止了以下端口(仅测试了 1024 以下的端口):

What ports exactly are meant by that appears to be up to the browser's Websocket implementation. My tests have shown that Chrome and Safari block the following ports (only ports below 1024 were tested):

  • 1:TCPMUX
  • 7:回声协议
  • 9:丢弃协议
  • 11:系统统计服务
  • 13:日间协议
  • 15:Netstat 服务
  • 17:每日名言
  • 19:字符生成器协议
  • 20:FTP
  • 21:FTP
  • 22:SSH
  • 23:远程登录
  • 25:SMTP
  • 37:时间协议
  • 42:名称服务器/WINS
  • 43:WHOIS
  • 53:DNS
  • 77:RJE 服务
  • 79:手指
  • 87:链接
  • 95:补充
  • 101:网卡主机名
  • 102:ISO-TSAP
  • 103:gppitnp
  • 104:ACR/NEMA
  • 109:POP2
  • 110:POP3
  • 111:SunRPC
  • 113:身份
  • 115:SFTP
  • 117:UUCP 路径服务
  • 119:NNTP
  • 123:NTP
  • 135:微软 EPMAP
  • 139:NetBIOS 会话服务
  • 143:IMAP
  • 179:BGP
  • 389:LDAP
  • 465:思科协议
  • 512:通信卫星
  • 513:登录
  • 514:系统日志
  • 515:行式打印机守护进程
  • 526:节奏
  • 530:RPC
  • 531:IRC
  • 532:网络新闻
  • 540:UUCP
  • 556:RFS
  • 563:NNTPS
  • 587:SMTP
  • 601:未知
  • 636:LDAPS
  • 993:IMAPS
  • 995:POP3S

相关服务取自 维基百科上的 TCP 和 UDP 端口号列表一>.

The associated services are taken from the list of TCP and UDP port numbers on Wikipeda.

这篇关于为什么浏览器会屏蔽某些端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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