UNPKG

8.94 kBMarkdownView Raw
1#network-diagnostics
2Network-diagnostics provides a library for diagnosing network problems.
3
4This module, network-diagnostics , is published under the MIT license. It is written by Nate Watson and Oluwafunmiwo Juda Sholola. Copyright 2015.
5
6## Installation Instructions
7
8### Local Installation
9
100. Goto the directory that the module is requred in: "cd *directory*".
11
121. Run this instruction:
13
14```
15npm install network-diagnostics
16```
17
182. Verify the installation
19
20### Global Installation
21
220. Ensure you have the right to perform global module installations.
23
241. Run this instruction:
25
26```
27npm install -g network-diagnostics
28```
29
302. Verify the installation
31
32### Installation Verification
33
340. Navigate to the directory of installation.
35
361. Run this instruction:
37
38```
39node diagnosticsTester.js
40```
41
422. It should print an array of numbers and a list of strings. If it does this, the installation ran smoothly. If this does not happen, reinstall.
43
44## Example
45
46```
47var diagnostics = require("./diagnostics");
48var diagnoseProcedure = diagnostics.diagnose(function(result){
49 console.dir(result);
50 for (var index = 0; index< result.length; index++) {
51 console.log(diagnostics.getError(result[index]));
52 }
53});
54```
55
56## Features
57
58network-diagnostics provides the following features:
59
60* Individual tests for several specific network problems, such as a lack of IPv6.
61* A consolidated method which performs the most common tests, and gives an array of error codes.
62* A method that takes an error code, and returns what it means.
63
64## Individual Tests
65### TestURL
66
67network-diagnostics provides two functions for changing the URL that HTTP is tested with. By default, the URL that is used for network tests is "google.com".
68
69```
70var result = diagnostics.getTestURL(); /*result would be "google.com"*/
71```
72
73```
74diagnostics.setTestURL("yahoo.com");
75```
76
77### diagnostics.haveIPv4 and haveIPv4Async
78This function returns a boolean value which states if an IPv4 connection is usable, not counting the one for localhost.
79```
80if (diagnostics.haveIPv4() == false) {
81 console.log("We have a problem.");
82}
83diagnostics.haveIPv4Async(function(result){
84 if (result==false) {
85 console.log("Somone go press that button on the router!");
86 }
87});
88```
89
90### diagnostics.haveIPv6 and haveIPv6Async
91This function returns a boolean value which states if an IPv6 connection is usable, not counting the one for localhost.
92```
93if (diagnostics.haveIPv6() == false) {
94 console.log("We have a bad network.");
95}
96diagnostics.haveIPv6Async(function(result){
97 if (result==true) {
98 console.log("Yay! We can comply with standards from the 90s!");
99 }
100});
101```
102
103### diagnostics.haveConnection and diagnostics.haveConnectionAsync
104This function returns a boolean value which states if an IP connection of any type is usable, not counting the one for localhost.
105```
106if (diagnostics.haveConnection() == false) {
107 console.log("This is all there is. The outside world is a myth.");
108}
109
110diagnostics.haveConnectionAsync(function(result){
111 if (result == true) {
112 console.log("There's a whole world out there!");
113 } else {
114 console.log("This is all there is. The outside world is a myth.");
115 }
116});
117```
118
119### diagnostics.haveDNS
120This function returns a boolean value which states if it's possible to perform non-cached DNS lookups.
121```
122var checkDNS = diagnostics.haveDNS(function(result){
123 if (result == false) {
124 console.log("Start memorizing numbers. DNS isn't working.");
125 }
126});
127```
128
129### diagnostics.haveHTTP
130This function returns a boolean value which states if it's possible to perform non-cached HTTP requests.
131```
132var checkHTTP = diagnostics.haveHTTP(function(result){
133 if (result == false) {
134 console.log("Don't worry, stackoverflow uses https, not http.");
135 }
136});
137```
138
139### diagnostics.haveHTTPS
140This function returns a boolean value which states if it's possible to perform non-cached HTTP requests.
141```
142var checkHTTPS = diagnostics.haveHTTPS(function(result){
143 if (result == false) {
144 console.log("Uh oh. Without HTTPS, we can't get to stackoverflow to solve the problem we just found!");
145 }
146});
147```
148### diagnostics.havePing
149This function returns a boolean value which states if ping is usable. Uses a callback function.
150```
151var checkPing = diagnostics.havePing(function(result){
152 if (result == true) {
153 console.log("ping works");
154 } else {
155 console.log("ping does not work");
156 }
157});
158```
159
160### diagnostics.haveInsecureImap and diagnostics.haveSecureImap
161These functions check if IMAP is usable, with and without security. Callback based. Note: These functions are not in the standard test procedure, because they need accounts. Because they need accounts, you should probably have a dedicated diagnostics account which has almost no rights, since this can result in leaked passwords.
162
163```
164var config = {
165 user: "jeremie@gmail.com",
166 password: "jerlita",
167 host: "imap.gmail.com",
168};
169var checkInsecureImap = diagnostics.haveInsecureImap(config, function(result) {
170 if (result == true) {
171 console.log("insecure imap works");
172 } else {
173 console.log("insecure imap does not work");
174 }
175});
176var checkSecureImap = diagnostics.haveSecureImap(config, function(result) {
177 if (result == true) {
178 console.log("secure imap works");
179 } else {
180 console.log("secure imap does not work");
181 }
182});
183```
184
185#### config specification
186* user: Mandatory, account name.
187* password: default is "".
188* host: default is "localhost".
189* port: default is 143 or 993 depending on the enabling of security.
190
191### diagnostics.haveInsecurePop and diagnostics.haveSecurePop
192These functions check if Pop3 is usable, with and without security. Callback based. Note: These functions are not in the standard test procedure, because of design consistency.
193```
194var dealWithResult = function(result) {
195 if (result == true) {
196 console.log("This configuration is usable!");
197 } else {
198 console.log("This configuration is not usable! I'm going to blame comcast, even if that doesn't make sense!");
199 }
200};
201var host = "pop.yahoo.com"; /*I just came up with this, I don't think it's real, don't use it.*/
202diagnostics.haveSecurePop(dealWithResult, host);
203diagnostics.haveInsecurePop(dealWithResult, host);
204```
205
206Note: if host is not defined, "pop.google.com" will be used.
207
208### diagnostics.haveNTP
209This function takes a (URL or IP address) and a callback, and checks to see if an NTP connection is available from the address in question. "Thank you @moonpyk for porting the client to Node!". This function is not in the standard test procedure, because it requires input.
210```
211diagnostics.haveNTP("pool.ntp.org", function(result){
212 if (result==true) {
213 console.log("NTP is available from here.");
214 } else {
215 console.log("NTP is not available from here.");
216 }
217 return;
218});
219```
220
221## Standardized Test
222This function performs every network test in the script that does not require any complex input from the user. Tests that require complex input must be run explicitly. It then returns the results as a number array in a callback function.
223
224```
225var diagnoseProcedure = diagnostics.diagnose(function(result){
226 console.dir(result);
227 for (var index = 0; index< result.length; index++) {
228 console.log(diagnostics.getError(result[index]));
229 }
230});
231```
232
233## Error Code Lookups
234diagnostics.getError is a function takes a numerical error code, and returns a string that relates to it.
235
236```
237console.log(diagnostics.getError(80)); /*NoHTTPconnection*/
238```
239
240As a general rule, every error code is the default port of the protocol that was tested, with a few logical exceptions. These are the codes which the function will actually evaluate:
241
242| Num | Error |
243|-----|----------------------------|
244| 0 | "NormalNetworkActivity" |
245| 1 | "NoConnection" |
246| 4 | "NoIPv4Connection" |
247| 6 | "NoIPv6Connection" |
248| 7 | "DiagnosticsScriptFailure" |
249| 8 | "PingNotUsable" |
250| 53 | "NoDNS" |
251| 80 | "NoHTTPconnection" |
252| 110 | "NoInsecurePOP3" |
253| 123 | "NoNTP" |
254| 143 | "NoInsecureIMAP" |
255| 443 | "NoHTTPSconnection" |
256| 993 | "NoSecureIMAP" |
257| 995 | "NoSecurePOP3" |
258
259These error codes are going to be used in the future when tests are written for them. Until that point, they are not directly usable.
260
261| Num | Error |
262|-----|-----------------------|
263| 20 | "FTPFailure" |
264| 22 | "SSHfailure" |
265| 23 | "TelnetFailure" |
266| 25 | "SMTPfailure" |
267| 37 | "TimeProtocolFailure" |
268| 70 | "NoGopher" |
269| 81 | "NoTor" |
270| 88 | "NoKerberos" |
271| 161 | "NoSNMP" |
272| 194 | "NoIRC" |
273| 5222| "NoXMPP" |