UNPKG

5.88 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
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}
83```
84
85### diagnostics.haveIPv6
86This function returns a boolean value which states if an IPv6 connection is usable, not counting the one for localhost.
87```
88if (diagnostics.haveIPv6() == false) {
89 console.log("We have a bad network.");
90}
91```
92
93### diagnostics.haveConnection
94This function returns a boolean value which states if an IP connection of any type is usable, not counting the one for localhost.
95```
96if (diagnostics.haveConnection() == false) {
97 console.log("This is all there is. The outside world is a myth.");
98}
99```
100
101### diagnostics.haveDNS
102This function returns a boolean value which states if it's possible to perform non-cached DNS lookups.
103```
104var checkDNS = diagnostics.haveDNS(function(result){
105 if (result == false) {
106 console.log("Start memorizing numbers. DNS isn't working.");
107 }
108});
109```
110
111### diagnostics.haveHTTP
112This function returns a boolean value which states if it's possible to perform non-cached HTTP requests.
113```
114var checkHTTP = diagnostics.haveHTTP(function(result){
115 if (result == false) {
116 console.log("Don't worry, stackoverflow uses https, not http.");
117 }
118});
119```
120
121### diagnostics.haveHTTPS
122This function returns a boolean value which states if it's possible to perform non-cached HTTP requests.
123```
124var checkHTTPS = diagnostics.haveHTTPS(function(result){
125 if (result == false) {
126 console.log("Uh oh. Without HTTPS, we can't get to stackoverflow to solve the problem we just found!");
127 }
128});
129```
130### diagnostics.havePing
131This function returns a boolean value which states if ping is usable. Uses a callback function.
132```
133var checkPing = diagnostics.havePing(function(result){
134 if (result == true) {
135 console.log("ping works");
136 } else {
137 console.log("ping does not work");
138 }
139});
140```
141
142##Standardized Test
143This 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.
144
145```
146var diagnoseProcedure = diagnostics.diagnose(function(result){
147 console.dir(result);
148 for (var index = 0; index< result.length; index++) {
149 console.log(diagnostics.getError(result[index]));
150 }
151});
152```
153
154##Error Code Lookups
155diagnostics.getError is a function takes a numerical error code, and returns a string that relates to it.
156```
157console.log(diagnostics.getError(80)); /*NoHTTPconnection*/
158```
159
160As 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:
161
162| Num | Error |
163|-----|----------------------------|
164| 0 | "NormalNetworkActivity" |
165| 1 | "NoConnection" |
166| 4 | "NoIPv4Connection" |
167| 6 | "NoIPv6Connection" |
168| 7 | "DiagnosticsScriptFailure" |
169| 8 | "PingNotUsable" |
170| 53 | "NoDNS" |
171| 80 | "NoHTTPconnection" |
172| 443 | "NoHTTPSconnection" |
173
174These error codes are going to be used in the future when tests are written for them. Until that point, they are not directly usable.
175
176| Num | Error |
177|-----|-----------------------|
178| 20 | "FTPFailure" |
179| 22 | "SSHfailure" |
180| 23 | "TelnetFailure" |
181| 25 | "SMTPfailure" |
182| 37 | "TimeProtocolFailure" |
183| 70 | "NoGopher" |
184| 81 | "NoTor" |
185| 88 | "NoKerberos" |
186| 110 | "NoInsecurePOP3" |
187| 143 | "NoInsecureIMAP" |
188| 161 | "NoSNMP" |
189| 194 | "NoIRC" |
190| 993 | "NoSecureIMAP" |
191| 995 | "NoSecurePOP3" |