1 | #network-diagnostics
|
2 | Network-diagnostics provides a library for diagnosing network problems.
|
3 |
|
4 | This 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 |
|
10 | 0. Goto the directory that the module is requred in: "cd *directory*".
|
11 |
|
12 | 1. Run this instruction:
|
13 |
|
14 | ```
|
15 | npm install network-diagnostics
|
16 | ```
|
17 |
|
18 | 2. Verify the installation
|
19 |
|
20 | ### Global Installation
|
21 |
|
22 | 0. Ensure you have the right to perform global module installations.
|
23 |
|
24 | 1. Run this instruction:
|
25 |
|
26 | ```
|
27 | npm install -g network-diagnostics
|
28 | ```
|
29 |
|
30 | 2. Verify the installation
|
31 |
|
32 | ### Installation Verification
|
33 |
|
34 | 0. Navigate to the directory of installation.
|
35 |
|
36 | 1. Run this instruction:
|
37 |
|
38 | ```
|
39 | node diagnosticsTester.js
|
40 | ```
|
41 |
|
42 | 2. 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 | ```
|
47 | var diagnostics = require("./diagnostics");
|
48 | var 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 |
|
58 | network-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 |
|
67 | network-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 | ```
|
70 | var result = diagnostics.getTestURL(); /*result would be "google.com"*/
|
71 | ```
|
72 |
|
73 | ```
|
74 | diagnostics.setTestURL("yahoo.com");
|
75 | ```
|
76 |
|
77 | ### diagnostics.haveIPv4
|
78 | This function returns a boolean value which states if an IPv4 connection is usable, not counting the one for localhost.
|
79 | ```
|
80 | if (diagnostics.haveIPv4() == false) {
|
81 | console.log("We have a problem.");
|
82 | }
|
83 | ```
|
84 |
|
85 | ### diagnostics.haveIPv6
|
86 | This function returns a boolean value which states if an IPv6 connection is usable, not counting the one for localhost.
|
87 | ```
|
88 | if (diagnostics.haveIPv6() == false) {
|
89 | console.log("We have a bad network.");
|
90 | }
|
91 | ```
|
92 |
|
93 | ### diagnostics.haveConnection
|
94 | This function returns a boolean value which states if an IP connection of any type is usable, not counting the one for localhost.
|
95 | ```
|
96 | if (diagnostics.haveConnection() == false) {
|
97 | console.log("This is all there is. The outside world is a myth.");
|
98 | }
|
99 | ```
|
100 |
|
101 | ### diagnostics.haveDNS
|
102 | This function returns a boolean value which states if it's possible to perform non-cached DNS lookups.
|
103 | ```
|
104 | var 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
|
112 | This function returns a boolean value which states if it's possible to perform non-cached HTTP requests.
|
113 | ```
|
114 | var 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
|
122 | This function returns a boolean value which states if it's possible to perform non-cached HTTP requests.
|
123 | ```
|
124 | var 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 |
|
131 | ##Standardized Test
|
132 | This 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.
|
133 |
|
134 | ```
|
135 | var diagnoseProcedure = diagnostics.diagnose(function(result){
|
136 | console.dir(result);
|
137 | for (var index = 0; index< result.length; index++) {
|
138 | console.log(diagnostics.getError(result[index]));
|
139 | }
|
140 | });
|
141 | ```
|
142 |
|
143 | ##Error Code Lookups
|
144 | diagnostics.getError is a function takes a numerical error code, and returns a string that relates to it.
|
145 | ```
|
146 | console.log(diagnostics.getError(80)); /*NoHTTPconnection*/
|
147 | ```
|
148 |
|
149 | As 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:
|
150 |
|
151 | These error codes are going to be used in the future when tests are written for them. Until that point, they are not directly usable.
|
152 |
|
153 | | Num | Error |
|
154 | |-----|----------------------------|
|
155 | | 0 | "NormalNetworkActivity" |
|
156 | | 1 | "NoConnection" |
|
157 | | 4 | "NoIPv4Connection" |
|
158 | | 6 | "NoIPv6Connection" |
|
159 | | 7 | "DiagnosticsScriptFailure" |
|
160 | | 53 | "NoDNS" |
|
161 | | 80 | "NoHTTPconnection" |
|
162 | | 443 | "NoHTTPSconnection" | |
\ | No newline at end of file |