63
client.connect(startPort, '127.0.0.1');
64
}
66
>
// Reference: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/net/base/port_util.cc#56
67
>
export const BROWSER_RESTRICTED_PORTS: Record<number, boolean> = {
68
>
1: true, // tcpmux
69
>
7: true, // echo
70
>
9: true, // discard
71
>
11: true, // systat
72
>
13: true, // daytime
73
>
15: true, // netstat
74
>
17: true, // qotd
75
>
19: true, // chargen
76
>
20: true, // ftp data
77
>
21: true, // ftp access
78
>
22: true, // ssh
79
>
23: true, // telnet
80
>
25: true, // smtp
81
>
37: true, // time
82
>
42: true, // name
83
>
43: true, // nicname
84
>
53: true, // domain
85
>
69: true, // tftp
86
>
77: true, // priv-rjs
87
>
79: true, // finger
88
>
87: true, // ttylink
89
>
95: true, // supdup
90
>
101: true, // hostriame
91
>
102: true, // iso-tsap
92
>
103: true, // gppitnp
93
>
104: true, // acr-nema
94
>
109: true, // pop2
95
>
110: true, // pop3
96
>
111: true, // sunrpc
97
>
113: true, // auth
98
>
115: true, // sftp
99
>
117: true, // uucp-path
100
>
119: true, // nntp
101
>
123: true, // NTP
102
>
135: true, // loc-srv /epmap
103
>
137: true, // netbios
104
>
139: true, // netbios
105
>
143: true, // imap2
106
>
161: true, // snmp
107
>
179: true, // BGP
108
>
389: true, // ldap
109
>
427: true, // SLP (Also used by Apple Filing Protocol)
110
>
465: true, // smtp+ssl
111
>
512: true, // print / exec
112
>
513: true, // login
113
>
514: true, // shell
114
>
515: true, // printer
115
>
526: true, // tempo
116
>
530: true, // courier
117
>
531: true, // chat
118
>
532: true, // netnews
119
>
540: true, // uucp
120
>
548: true, // AFP (Apple Filing Protocol)
121
>
554: true, // rtsp
122
>
556: true, // remotefs
123
>
563: true, // nntp+ssl
124
>
587: true, // smtp (rfc6409)
125
>
601: true, // syslog-conn (rfc3195)
126
>
636: true, // ldap+ssl
127
>
989: true, // ftps-data
128
>
990: true, // ftps
129
>
993: true, // ldap+ssl
130
>
995: true, // pop3+ssl
131
>
1719: true, // h323gatestat
132
>
1720: true, // h323hostcall
133
>
1723: true, // pptp
134
>
2049: true, // nfs
135
>
3659: true, // apple-sasl / PasswordServer
136
>
4045: true, // lockd
137
>
5060: true, // sip
138
>
5061: true, // sips
139
>
6000: true, // X11
140
>
6566: true, // sane-port
141
>
6665: true, // Alternate IRC [Apple addition]
142
>
6666: true, // Alternate IRC [Apple addition]
143
>
6667: true, // Standard IRC [Apple addition]
144
>
6668: true, // Alternate IRC [Apple addition]
145
>
6669: true, // Alternate IRC [Apple addition]
146
>
6697: true, // IRC + TLS
147
>
10080: true // Amanda
148
>
};
149
>
150
>
export function isPortFree(port: number, timeout: number): Promise<boolean> {
151
return findFreePortFaster(port, 0, timeout).then(port => port !== 0);
152
}
154
>
interface ServerError {
155
>
code?: string;
156
>
}
157
>
158
>
/**
159
>
* Uses listen instead of connect. Is faster, but if there is another listener on 0.0.0.0 then this will take 127.0.0.1 from that listener.
160
>
*/
161
>
export function findFreePortFaster(startPort: number, giveUpAfter: number, timeout: number, hostname: string = '127.0.0.1'): Promise<number> {
162
let resolved: boolean = false;
163
let timeoutHandle: Timeout | undefined = undefined;