systeminformation 5.33.3 → 6.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (494) hide show
  1. package/README.md +873 -957
  2. package/dist/audio.d.ts +1 -0
  3. package/dist/audio.js +18 -0
  4. package/dist/baseboard.d.ts +1 -0
  5. package/dist/baseboard.js +17 -0
  6. package/dist/battery.d.ts +1 -0
  7. package/dist/battery.js +19 -0
  8. package/dist/bios.d.ts +1 -0
  9. package/dist/bios.js +17 -0
  10. package/dist/block-devices.d.ts +1 -0
  11. package/dist/block-devices.js +17 -0
  12. package/dist/bluetooth.d.ts +1 -0
  13. package/dist/bluetooth.js +17 -0
  14. package/dist/bsd/battery.d.ts +2 -0
  15. package/dist/bsd/battery.js +27 -0
  16. package/dist/bsd/cpu-cache.d.ts +1 -0
  17. package/dist/bsd/cpu-cache.js +37 -0
  18. package/dist/bsd/cpu-flags.d.ts +1 -0
  19. package/dist/bsd/cpu-flags.js +28 -0
  20. package/dist/bsd/cpu-temperature.d.ts +1 -0
  21. package/dist/bsd/cpu-temperature.js +29 -0
  22. package/dist/bsd/cpu.d.ts +1 -0
  23. package/dist/bsd/cpu.js +98 -0
  24. package/dist/bsd/index.d.ts +38 -0
  25. package/dist/bsd/index.js +85 -0
  26. package/dist/bsd/mem.d.ts +1 -0
  27. package/dist/bsd/mem.js +37 -0
  28. package/dist/bsd/network-stats.d.ts +2 -0
  29. package/dist/bsd/network-stats.js +92 -0
  30. package/dist/bsd/os-info.d.ts +21 -0
  31. package/dist/bsd/os-info.js +38 -0
  32. package/dist/bsd/uuid.d.ts +2 -0
  33. package/dist/bsd/uuid.js +30 -0
  34. package/dist/camera.d.ts +1 -0
  35. package/dist/camera.js +17 -0
  36. package/dist/chassis.d.ts +1 -0
  37. package/dist/chassis.js +17 -0
  38. package/dist/cli.d.ts +2 -0
  39. package/dist/cli.js +107 -0
  40. package/dist/common/codepage.d.ts +1 -0
  41. package/dist/common/codepage.js +43 -0
  42. package/dist/common/const.d.ts +25 -0
  43. package/dist/common/const.js +26 -0
  44. package/dist/common/cpu.d.ts +2 -0
  45. package/dist/common/cpu.js +12 -0
  46. package/dist/common/darwin.d.ts +6 -0
  47. package/dist/common/darwin.js +266 -0
  48. package/dist/common/datetime.d.ts +9 -0
  49. package/dist/common/datetime.js +161 -0
  50. package/dist/common/defaults.d.ts +25 -0
  51. package/dist/common/defaults.js +299 -0
  52. package/dist/common/exec.d.ts +10 -0
  53. package/dist/common/exec.js +69 -0
  54. package/dist/common/files.d.ts +2 -0
  55. package/dist/common/files.js +39 -0
  56. package/dist/common/filesys.d.ts +11 -0
  57. package/dist/common/filesys.js +282 -0
  58. package/dist/common/host.d.ts +2 -0
  59. package/dist/common/host.js +67 -0
  60. package/dist/common/index.d.ts +12 -0
  61. package/dist/common/index.js +146 -0
  62. package/dist/common/internet.d.ts +1 -0
  63. package/dist/common/internet.js +47 -0
  64. package/dist/common/mappings.d.ts +55 -0
  65. package/dist/common/mappings.js +4133 -0
  66. package/dist/common/network.d.ts +8 -0
  67. package/dist/common/network.js +162 -0
  68. package/dist/common/nvidia.d.ts +22 -0
  69. package/dist/common/nvidia.js +159 -0
  70. package/dist/common/parse.d.ts +13 -0
  71. package/dist/common/parse.js +157 -0
  72. package/dist/common/raspberry.d.ts +5 -0
  73. package/dist/common/raspberry.js +277 -0
  74. package/dist/common/security.d.ts +31 -0
  75. package/dist/common/security.js +241 -0
  76. package/dist/common/types.d.ts +992 -0
  77. package/dist/common/types.js +2 -0
  78. package/dist/common/windows.d.ts +58 -0
  79. package/dist/common/windows.js +292 -0
  80. package/dist/cpu-cache.d.ts +1 -0
  81. package/dist/cpu-cache.js +19 -0
  82. package/dist/cpu-current-load.d.ts +2 -0
  83. package/dist/cpu-current-load.js +249 -0
  84. package/dist/cpu-current-speed.d.ts +3 -0
  85. package/dist/cpu-current-speed.js +84 -0
  86. package/dist/cpu-flags.d.ts +1 -0
  87. package/dist/cpu-flags.js +19 -0
  88. package/dist/cpu-full-load.d.ts +1 -0
  89. package/dist/cpu-full-load.js +30 -0
  90. package/dist/cpu-temperature.d.ts +1 -0
  91. package/dist/cpu-temperature.js +19 -0
  92. package/dist/cpu.d.ts +1 -0
  93. package/dist/cpu.js +19 -0
  94. package/dist/darwin/audio.d.ts +2 -0
  95. package/dist/darwin/audio.js +46 -0
  96. package/dist/darwin/baseboard.d.ts +1 -0
  97. package/dist/darwin/baseboard.js +48 -0
  98. package/dist/darwin/battery.d.ts +2 -0
  99. package/dist/darwin/battery.js +65 -0
  100. package/dist/darwin/bios.d.ts +1 -0
  101. package/dist/darwin/bios.js +45 -0
  102. package/dist/darwin/block-devices.d.ts +2 -0
  103. package/dist/darwin/block-devices.js +101 -0
  104. package/dist/darwin/bluetooth.d.ts +3 -0
  105. package/dist/darwin/bluetooth.js +84 -0
  106. package/dist/darwin/camera.d.ts +2 -0
  107. package/dist/darwin/camera.js +55 -0
  108. package/dist/darwin/chassis.d.ts +2 -0
  109. package/dist/darwin/chassis.js +32 -0
  110. package/dist/darwin/cpu-cache.d.ts +2 -0
  111. package/dist/darwin/cpu-cache.js +29 -0
  112. package/dist/darwin/cpu-flags.d.ts +1 -0
  113. package/dist/darwin/cpu-flags.js +16 -0
  114. package/dist/darwin/cpu-temperature.d.ts +1 -0
  115. package/dist/darwin/cpu-temperature.js +44 -0
  116. package/dist/darwin/cpu.d.ts +1 -0
  117. package/dist/darwin/cpu.js +69 -0
  118. package/dist/darwin/disk-layout.d.ts +2 -0
  119. package/dist/darwin/disk-layout.js +231 -0
  120. package/dist/darwin/disks-io.d.ts +2 -0
  121. package/dist/darwin/disks-io.js +56 -0
  122. package/dist/darwin/displays.d.ts +2 -0
  123. package/dist/darwin/displays.js +98 -0
  124. package/dist/darwin/fs-open-files.d.ts +2 -0
  125. package/dist/darwin/fs-open-files.js +27 -0
  126. package/dist/darwin/fs-stats.d.ts +2 -0
  127. package/dist/darwin/fs-stats.js +47 -0
  128. package/dist/darwin/gpu.d.ts +2 -0
  129. package/dist/darwin/gpu.js +55 -0
  130. package/dist/darwin/index.d.ts +56 -0
  131. package/dist/darwin/index.js +122 -0
  132. package/dist/darwin/keyboard.d.ts +2 -0
  133. package/dist/darwin/keyboard.js +73 -0
  134. package/dist/darwin/mem-layout.d.ts +2 -0
  135. package/dist/darwin/mem-layout.js +60 -0
  136. package/dist/darwin/mem.d.ts +2 -0
  137. package/dist/darwin/mem.js +50 -0
  138. package/dist/darwin/mouse.d.ts +2 -0
  139. package/dist/darwin/mouse.js +78 -0
  140. package/dist/darwin/network-connections.d.ts +2 -0
  141. package/dist/darwin/network-connections.js +98 -0
  142. package/dist/darwin/network-gateway-default.d.ts +1 -0
  143. package/dist/darwin/network-gateway-default.js +26 -0
  144. package/dist/darwin/network-interface-default.d.ts +2 -0
  145. package/dist/darwin/network-interface-default.js +41 -0
  146. package/dist/darwin/network-interfaces.d.ts +2 -0
  147. package/dist/darwin/network-interfaces.js +205 -0
  148. package/dist/darwin/network-stats.d.ts +2 -0
  149. package/dist/darwin/network-stats.js +86 -0
  150. package/dist/darwin/npm.d.ts +1 -0
  151. package/dist/darwin/npm.js +5 -0
  152. package/dist/darwin/npu.d.ts +2 -0
  153. package/dist/darwin/npu.js +41 -0
  154. package/dist/darwin/os-info.d.ts +1 -0
  155. package/dist/darwin/os-info.js +110 -0
  156. package/dist/darwin/pci.d.ts +2 -0
  157. package/dist/darwin/pci.js +37 -0
  158. package/dist/darwin/printer.d.ts +2 -0
  159. package/dist/darwin/printer.js +45 -0
  160. package/dist/darwin/software.d.ts +2 -0
  161. package/dist/darwin/software.js +39 -0
  162. package/dist/darwin/system.d.ts +1 -0
  163. package/dist/darwin/system.js +29 -0
  164. package/dist/darwin/thunderbolt.d.ts +1 -0
  165. package/dist/darwin/thunderbolt.js +53 -0
  166. package/dist/darwin/usb.d.ts +3 -0
  167. package/dist/darwin/usb.js +69 -0
  168. package/dist/darwin/users.d.ts +2 -0
  169. package/dist/darwin/users.js +13 -0
  170. package/dist/darwin/uuid.d.ts +2 -0
  171. package/dist/darwin/uuid.js +39 -0
  172. package/dist/darwin/wifi-connections.d.ts +2 -0
  173. package/dist/darwin/wifi-connections.js +60 -0
  174. package/dist/darwin/wifi-interfaces.d.ts +2 -0
  175. package/dist/darwin/wifi-interfaces.js +27 -0
  176. package/dist/darwin/wifi-networks.d.ts +2 -0
  177. package/dist/darwin/wifi-networks.js +61 -0
  178. package/dist/disk-layout.d.ts +1 -0
  179. package/dist/disk-layout.js +17 -0
  180. package/dist/disks-io.d.ts +1 -0
  181. package/dist/disks-io.js +17 -0
  182. package/dist/displays.d.ts +1 -0
  183. package/dist/displays.js +17 -0
  184. package/dist/docker-socket.d.ts +11 -0
  185. package/dist/docker-socket.js +113 -0
  186. package/dist/docker.d.ts +102 -0
  187. package/dist/docker.js +532 -0
  188. package/dist/fs-open-files.d.ts +1 -0
  189. package/dist/fs-open-files.js +17 -0
  190. package/dist/fs-size.d.ts +1 -0
  191. package/dist/fs-size.js +23 -0
  192. package/dist/fs-stats.d.ts +1 -0
  193. package/dist/fs-stats.js +17 -0
  194. package/dist/get-data.d.ts +110 -0
  195. package/dist/get-data.js +151 -0
  196. package/dist/get.d.ts +5 -0
  197. package/dist/get.js +117 -0
  198. package/dist/gpu.d.ts +1 -0
  199. package/dist/gpu.js +17 -0
  200. package/dist/index.d.ts +59 -0
  201. package/dist/index.js +130 -0
  202. package/dist/inet-checksite.d.ts +1 -0
  203. package/dist/inet-checksite.js +11 -0
  204. package/dist/inet-latency.d.ts +1 -0
  205. package/dist/inet-latency.js +17 -0
  206. package/dist/keyboard.d.ts +1 -0
  207. package/dist/keyboard.js +17 -0
  208. package/dist/linux/audio.d.ts +2 -0
  209. package/dist/linux/audio.js +67 -0
  210. package/dist/linux/baseboard.d.ts +1 -0
  211. package/dist/linux/baseboard.js +81 -0
  212. package/dist/linux/battery.d.ts +2 -0
  213. package/dist/linux/battery.js +88 -0
  214. package/dist/linux/bios.d.ts +2 -0
  215. package/dist/linux/bios.js +55 -0
  216. package/dist/linux/block-devices.d.ts +2 -0
  217. package/dist/linux/block-devices.js +30 -0
  218. package/dist/linux/bluetooth.d.ts +2 -0
  219. package/dist/linux/bluetooth.js +86 -0
  220. package/dist/linux/camera.d.ts +2 -0
  221. package/dist/linux/camera.js +63 -0
  222. package/dist/linux/chassis.d.ts +1 -0
  223. package/dist/linux/chassis.js +41 -0
  224. package/dist/linux/cpu-cache.d.ts +1 -0
  225. package/dist/linux/cpu-cache.js +35 -0
  226. package/dist/linux/cpu-flags.d.ts +1 -0
  227. package/dist/linux/cpu-flags.js +33 -0
  228. package/dist/linux/cpu-temperature.d.ts +1 -0
  229. package/dist/linux/cpu-temperature.js +179 -0
  230. package/dist/linux/cpu.d.ts +1 -0
  231. package/dist/linux/cpu.js +135 -0
  232. package/dist/linux/disk-layout.d.ts +2 -0
  233. package/dist/linux/disk-layout.js +151 -0
  234. package/dist/linux/disks-io.d.ts +2 -0
  235. package/dist/linux/disks-io.js +58 -0
  236. package/dist/linux/displays.d.ts +2 -0
  237. package/dist/linux/displays.js +193 -0
  238. package/dist/linux/fs-open-files.d.ts +2 -0
  239. package/dist/linux/fs-open-files.js +44 -0
  240. package/dist/linux/fs-size.d.ts +2 -0
  241. package/dist/linux/fs-size.js +157 -0
  242. package/dist/linux/fs-stats.d.ts +2 -0
  243. package/dist/linux/fs-stats.js +65 -0
  244. package/dist/linux/gpu.d.ts +2 -0
  245. package/dist/linux/gpu.js +273 -0
  246. package/dist/linux/index.d.ts +56 -0
  247. package/dist/linux/index.js +122 -0
  248. package/dist/linux/inet-latency.d.ts +1 -0
  249. package/dist/linux/inet-latency.js +39 -0
  250. package/dist/linux/keyboard.d.ts +2 -0
  251. package/dist/linux/keyboard.js +61 -0
  252. package/dist/linux/mem-layout.d.ts +2 -0
  253. package/dist/linux/mem-layout.js +112 -0
  254. package/dist/linux/mem.d.ts +2 -0
  255. package/dist/linux/mem.js +61 -0
  256. package/dist/linux/mouse.d.ts +2 -0
  257. package/dist/linux/mouse.js +73 -0
  258. package/dist/linux/network-connections.d.ts +2 -0
  259. package/dist/linux/network-connections.js +114 -0
  260. package/dist/linux/network-gateway-default.d.ts +1 -0
  261. package/dist/linux/network-gateway-default.js +22 -0
  262. package/dist/linux/network-interface-default.d.ts +2 -0
  263. package/dist/linux/network-interface-default.js +46 -0
  264. package/dist/linux/network-interfaces.d.ts +3 -0
  265. package/dist/linux/network-interfaces.js +353 -0
  266. package/dist/linux/network-stats.d.ts +2 -0
  267. package/dist/linux/network-stats.js +99 -0
  268. package/dist/linux/npm.d.ts +1 -0
  269. package/dist/linux/npm.js +5 -0
  270. package/dist/linux/npu.d.ts +2 -0
  271. package/dist/linux/npu.js +77 -0
  272. package/dist/linux/os-info.d.ts +1 -0
  273. package/dist/linux/os-info.js +104 -0
  274. package/dist/linux/pci.d.ts +2 -0
  275. package/dist/linux/pci.js +56 -0
  276. package/dist/linux/printer.d.ts +2 -0
  277. package/dist/linux/printer.js +80 -0
  278. package/dist/linux/process-load.d.ts +2 -0
  279. package/dist/linux/process-load.js +164 -0
  280. package/dist/linux/processes.d.ts +2 -0
  281. package/dist/linux/processes.js +358 -0
  282. package/dist/linux/services.d.ts +2 -0
  283. package/dist/linux/services.js +222 -0
  284. package/dist/linux/software.d.ts +2 -0
  285. package/dist/linux/software.js +110 -0
  286. package/dist/linux/system.d.ts +1 -0
  287. package/dist/linux/system.js +186 -0
  288. package/dist/linux/thunderbolt.d.ts +2 -0
  289. package/dist/linux/thunderbolt.js +51 -0
  290. package/dist/linux/time.d.ts +6 -0
  291. package/dist/linux/time.js +28 -0
  292. package/dist/linux/usb.d.ts +2 -0
  293. package/dist/linux/usb.js +62 -0
  294. package/dist/linux/users.d.ts +2 -0
  295. package/dist/linux/users.js +102 -0
  296. package/dist/linux/uuid.d.ts +2 -0
  297. package/dist/linux/uuid.js +44 -0
  298. package/dist/linux/wifi-connections.d.ts +2 -0
  299. package/dist/linux/wifi-connections.js +196 -0
  300. package/dist/linux/wifi-interfaces.d.ts +2 -0
  301. package/dist/linux/wifi-interfaces.js +96 -0
  302. package/dist/linux/wifi-networks.d.ts +2 -0
  303. package/dist/linux/wifi-networks.js +176 -0
  304. package/dist/mem-layout.d.ts +1 -0
  305. package/dist/mem-layout.js +17 -0
  306. package/dist/mem.d.ts +1 -0
  307. package/dist/mem.js +19 -0
  308. package/dist/mouse.d.ts +1 -0
  309. package/dist/mouse.js +17 -0
  310. package/dist/network-connections.d.ts +1 -0
  311. package/dist/network-connections.js +17 -0
  312. package/dist/network-gateway-default.d.ts +1 -0
  313. package/dist/network-gateway-default.js +17 -0
  314. package/dist/network-interface-default.d.ts +1 -0
  315. package/dist/network-interface-default.js +17 -0
  316. package/dist/network-interfaces.d.ts +1 -0
  317. package/dist/network-interfaces.js +18 -0
  318. package/dist/network-stats.d.ts +1 -0
  319. package/dist/network-stats.js +19 -0
  320. package/dist/npm.d.ts +2 -0
  321. package/dist/npm.js +22 -0
  322. package/dist/npu.d.ts +1 -0
  323. package/dist/npu.js +17 -0
  324. package/dist/observe.d.ts +5 -0
  325. package/dist/observe.js +16 -0
  326. package/dist/os-info.d.ts +1 -0
  327. package/dist/os-info.js +21 -0
  328. package/dist/pci.d.ts +1 -0
  329. package/dist/pci.js +17 -0
  330. package/dist/printer.d.ts +1 -0
  331. package/dist/printer.js +17 -0
  332. package/dist/process-load.d.ts +1 -0
  333. package/dist/process-load.js +15 -0
  334. package/dist/processes.d.ts +1 -0
  335. package/dist/processes.js +15 -0
  336. package/dist/services.d.ts +1 -0
  337. package/dist/services.js +15 -0
  338. package/dist/shell.d.ts +1 -0
  339. package/dist/shell.js +16 -0
  340. package/dist/software.d.ts +1 -0
  341. package/dist/software.js +17 -0
  342. package/dist/sun/index.d.ts +17 -0
  343. package/dist/sun/index.js +43 -0
  344. package/dist/sun/inet-latency.d.ts +1 -0
  345. package/dist/sun/inet-latency.js +30 -0
  346. package/dist/sun/os-info.d.ts +1 -0
  347. package/dist/sun/os-info.js +26 -0
  348. package/dist/sun/users.d.ts +2 -0
  349. package/dist/sun/users.js +13 -0
  350. package/dist/system.d.ts +1 -0
  351. package/dist/system.js +17 -0
  352. package/dist/thunderbolt.d.ts +1 -0
  353. package/dist/thunderbolt.js +17 -0
  354. package/dist/time.d.ts +6 -0
  355. package/dist/time.js +28 -0
  356. package/dist/usb.d.ts +1 -0
  357. package/dist/usb.js +17 -0
  358. package/dist/users.d.ts +1 -0
  359. package/dist/users.js +21 -0
  360. package/dist/uuid.d.ts +1 -0
  361. package/dist/uuid.js +19 -0
  362. package/dist/version.d.ts +1 -0
  363. package/dist/version.js +16 -0
  364. package/dist/versions.d.ts +2 -0
  365. package/dist/versions.js +1122 -0
  366. package/dist/virtualbox.d.ts +2 -0
  367. package/dist/virtualbox.js +89 -0
  368. package/dist/wifi-connections.d.ts +1 -0
  369. package/dist/wifi-connections.js +17 -0
  370. package/dist/wifi-interfaces.d.ts +1 -0
  371. package/dist/wifi-interfaces.js +17 -0
  372. package/dist/wifi-networks.d.ts +1 -0
  373. package/dist/wifi-networks.js +17 -0
  374. package/dist/windows/audio.d.ts +2 -0
  375. package/dist/windows/audio.js +23 -0
  376. package/dist/windows/baseboard.d.ts +1 -0
  377. package/dist/windows/baseboard.js +35 -0
  378. package/dist/windows/battery.d.ts +1 -0
  379. package/dist/windows/battery.js +81 -0
  380. package/dist/windows/bios.d.ts +1 -0
  381. package/dist/windows/bios.js +37 -0
  382. package/dist/windows/block-devices.d.ts +2 -0
  383. package/dist/windows/block-devices.js +48 -0
  384. package/dist/windows/bluetooth.d.ts +2 -0
  385. package/dist/windows/bluetooth.js +31 -0
  386. package/dist/windows/camera.d.ts +2 -0
  387. package/dist/windows/camera.js +47 -0
  388. package/dist/windows/chassis.d.ts +1 -0
  389. package/dist/windows/chassis.js +29 -0
  390. package/dist/windows/cpu-cache.d.ts +2 -0
  391. package/dist/windows/cpu-cache.js +59 -0
  392. package/dist/windows/cpu-flags.d.ts +1 -0
  393. package/dist/windows/cpu-flags.js +61 -0
  394. package/dist/windows/cpu-temperature.d.ts +1 -0
  395. package/dist/windows/cpu-temperature.js +32 -0
  396. package/dist/windows/cpu.d.ts +1 -0
  397. package/dist/windows/cpu.js +96 -0
  398. package/dist/windows/disk-layout.d.ts +2 -0
  399. package/dist/windows/disk-layout.js +112 -0
  400. package/dist/windows/disks-io.d.ts +2 -0
  401. package/dist/windows/disks-io.js +43 -0
  402. package/dist/windows/displays.d.ts +2 -0
  403. package/dist/windows/displays.js +213 -0
  404. package/dist/windows/fs-open-files.d.ts +2 -0
  405. package/dist/windows/fs-open-files.js +22 -0
  406. package/dist/windows/fs-size.d.ts +2 -0
  407. package/dist/windows/fs-size.js +47 -0
  408. package/dist/windows/fs-stats.d.ts +2 -0
  409. package/dist/windows/fs-stats.js +37 -0
  410. package/dist/windows/gpu.d.ts +2 -0
  411. package/dist/windows/gpu.js +128 -0
  412. package/dist/windows/index.d.ts +56 -0
  413. package/dist/windows/index.js +122 -0
  414. package/dist/windows/inet-latency.d.ts +1 -0
  415. package/dist/windows/inet-latency.js +34 -0
  416. package/dist/windows/keyboard.d.ts +2 -0
  417. package/dist/windows/keyboard.js +47 -0
  418. package/dist/windows/mem-layout.d.ts +2 -0
  419. package/dist/windows/mem-layout.js +39 -0
  420. package/dist/windows/mem.d.ts +2 -0
  421. package/dist/windows/mem.js +33 -0
  422. package/dist/windows/mouse.d.ts +2 -0
  423. package/dist/windows/mouse.js +64 -0
  424. package/dist/windows/network-connections.d.ts +2 -0
  425. package/dist/windows/network-connections.js +93 -0
  426. package/dist/windows/network-gateway-default.d.ts +1 -0
  427. package/dist/windows/network-gateway-default.js +36 -0
  428. package/dist/windows/network-interface-default.d.ts +2 -0
  429. package/dist/windows/network-interface-default.js +56 -0
  430. package/dist/windows/network-interfaces.d.ts +2 -0
  431. package/dist/windows/network-interfaces.js +346 -0
  432. package/dist/windows/network-stats.d.ts +2 -0
  433. package/dist/windows/network-stats.js +135 -0
  434. package/dist/windows/npm.d.ts +1 -0
  435. package/dist/windows/npm.js +5 -0
  436. package/dist/windows/npu.d.ts +2 -0
  437. package/dist/windows/npu.js +29 -0
  438. package/dist/windows/os-info.d.ts +1 -0
  439. package/dist/windows/os-info.js +65 -0
  440. package/dist/windows/pci.d.ts +2 -0
  441. package/dist/windows/pci.js +33 -0
  442. package/dist/windows/printer.d.ts +2 -0
  443. package/dist/windows/printer.js +36 -0
  444. package/dist/windows/process-load.d.ts +2 -0
  445. package/dist/windows/process-load.js +121 -0
  446. package/dist/windows/processes.d.ts +9 -0
  447. package/dist/windows/processes.js +139 -0
  448. package/dist/windows/services.d.ts +2 -0
  449. package/dist/windows/services.js +83 -0
  450. package/dist/windows/shell.d.ts +1 -0
  451. package/dist/windows/shell.js +19 -0
  452. package/dist/windows/software.d.ts +2 -0
  453. package/dist/windows/software.js +53 -0
  454. package/dist/windows/system.d.ts +1 -0
  455. package/dist/windows/system.js +98 -0
  456. package/dist/windows/thunderbolt.d.ts +2 -0
  457. package/dist/windows/thunderbolt.js +34 -0
  458. package/dist/windows/usb.d.ts +2 -0
  459. package/dist/windows/usb.js +37 -0
  460. package/dist/windows/users.d.ts +2 -0
  461. package/dist/windows/users.js +151 -0
  462. package/dist/windows/uuid.d.ts +2 -0
  463. package/dist/windows/uuid.js +28 -0
  464. package/dist/windows/wifi-connections.d.ts +2 -0
  465. package/dist/windows/wifi-connections.js +56 -0
  466. package/dist/windows/wifi-interfaces.d.ts +2 -0
  467. package/dist/windows/wifi-interfaces.js +45 -0
  468. package/dist/windows/wifi-networks.d.ts +2 -0
  469. package/dist/windows/wifi-networks.js +50 -0
  470. package/package.json +78 -12
  471. package/lib/audio.js +0 -277
  472. package/lib/battery.js +0 -334
  473. package/lib/bluetooth.js +0 -315
  474. package/lib/bluetoothVendors.js +0 -1138
  475. package/lib/cli.js +0 -100
  476. package/lib/cpu.js +0 -2285
  477. package/lib/docker.js +0 -791
  478. package/lib/dockerSocket.js +0 -117
  479. package/lib/filesystem.js +0 -1832
  480. package/lib/graphics.js +0 -1321
  481. package/lib/index.d.ts +0 -1051
  482. package/lib/index.js +0 -520
  483. package/lib/internet.js +0 -259
  484. package/lib/memory.js +0 -622
  485. package/lib/network.js +0 -2008
  486. package/lib/osinfo.js +0 -1321
  487. package/lib/printer.js +0 -209
  488. package/lib/processes.js +0 -1459
  489. package/lib/system.js +0 -855
  490. package/lib/usb.js +0 -309
  491. package/lib/users.js +0 -412
  492. package/lib/util.js +0 -2824
  493. package/lib/virtualbox.js +0 -116
  494. package/lib/wifi.js +0 -839
package/lib/network.js DELETED
@@ -1,2008 +0,0 @@
1
- 'use strict';
2
- // @ts-check
3
- // ==================================================================================
4
- // network.js
5
- // ----------------------------------------------------------------------------------
6
- // Description: System Information - library
7
- // for Node.js
8
- // Copyright: (c) 2014 - 2026
9
- // Author: Sebastian Hildebrandt
10
- // ----------------------------------------------------------------------------------
11
- // License: MIT
12
- // ==================================================================================
13
- // 9. Network
14
- // ----------------------------------------------------------------------------------
15
-
16
- const os = require('os');
17
- const exec = require('child_process').exec;
18
- const execSync = require('child_process').execSync;
19
- const execFileSync = require('child_process').execFileSync;
20
- const readFileSync = require('fs').readFileSync;
21
-
22
- const fs = require('fs');
23
- const util = require('./util');
24
-
25
- const _platform = process.platform;
26
-
27
- const _linux = _platform === 'linux' || _platform === 'android';
28
- const _darwin = _platform === 'darwin';
29
- const _windows = _platform === 'win32';
30
- const _freebsd = _platform === 'freebsd';
31
- const _openbsd = _platform === 'openbsd';
32
- const _netbsd = _platform === 'netbsd';
33
- const _sunos = _platform === 'sunos';
34
-
35
- const _network = {};
36
- let _default_iface = '';
37
- let _ifaces = {};
38
- let _dhcpNics = [];
39
- let _networkInterfaces = [];
40
- let _mac = {};
41
- let pathToIp;
42
-
43
- function getDefaultNetworkInterface() {
44
- let ifacename = '';
45
- let ifacenameFirst = '';
46
- try {
47
- const ifaces = os.networkInterfaces();
48
-
49
- let scopeid = 9999;
50
-
51
- // fallback - "first" external interface (sorted by scopeid)
52
- for (let dev in ifaces) {
53
- if ({}.hasOwnProperty.call(ifaces, dev)) {
54
- ifaces[dev].forEach((details) => {
55
- if (details && details.internal === false) {
56
- ifacenameFirst = ifacenameFirst || dev; // fallback if no scopeid
57
- if (details.scopeid && details.scopeid < scopeid) {
58
- ifacename = dev;
59
- scopeid = details.scopeid;
60
- }
61
- }
62
- });
63
- }
64
- }
65
- ifacename = ifacename || ifacenameFirst || '';
66
-
67
- if (_windows) {
68
- // https://www.inetdaemon.com/tutorials/internet/ip/routing/default_route.shtml
69
- let defaultIp = '';
70
- const cmd = 'netstat -r';
71
- const result = execSync(cmd, util.execOptsWin);
72
- const lines = result.toString().split(os.EOL);
73
- lines.forEach((line) => {
74
- line = line.replace(/\s+/g, ' ').trim();
75
- if (line.indexOf('0.0.0.0 0.0.0.0') > -1 && !/[a-zA-Z]/.test(line)) {
76
- const parts = line.split(' ');
77
- if (parts.length >= 5) {
78
- defaultIp = parts[parts.length - 2];
79
- }
80
- }
81
- });
82
- if (defaultIp) {
83
- for (let dev in ifaces) {
84
- if ({}.hasOwnProperty.call(ifaces, dev)) {
85
- ifaces[dev].forEach((details) => {
86
- if (details && details.address && details.address === defaultIp) {
87
- ifacename = dev;
88
- }
89
- });
90
- }
91
- }
92
- }
93
- }
94
- if (_linux) {
95
- const cmd = 'ip route 2> /dev/null | grep default';
96
- const result = execSync(cmd, util.execOptsLinux);
97
- const parts = result.toString().split('\n')[0].split(/\s+/);
98
- if (parts[0] === 'none' && parts[5]) {
99
- ifacename = parts[5];
100
- } else if (parts[4]) {
101
- ifacename = parts[4];
102
- }
103
-
104
- if (ifacename.indexOf(':') > -1) {
105
- ifacename = ifacename.split(':')[1].trim();
106
- }
107
- }
108
- if (_darwin || _freebsd || _openbsd || _netbsd || _sunos) {
109
- let cmd = '';
110
- if (_linux) {
111
- cmd = "ip route 2> /dev/null | grep default | awk '{print $5}'";
112
- }
113
- if (_darwin) {
114
- cmd = "route -n get default 2>/dev/null | grep interface: | awk '{print $2}'";
115
- }
116
- if (_freebsd || _openbsd || _netbsd || _sunos) {
117
- cmd = 'route get 0.0.0.0 | grep interface:';
118
- }
119
- const result = execSync(cmd);
120
- ifacename = result.toString().split('\n')[0];
121
- if (ifacename.indexOf(':') > -1) {
122
- ifacename = ifacename.split(':')[1].trim();
123
- }
124
- }
125
- } catch {
126
- util.noop();
127
- }
128
- if (ifacename) {
129
- _default_iface = ifacename;
130
- }
131
- return _default_iface;
132
- }
133
-
134
- exports.getDefaultNetworkInterface = getDefaultNetworkInterface;
135
-
136
- function getMacAddresses() {
137
- let iface = '';
138
- let mac = '';
139
- const result = {};
140
- if (_linux || _freebsd || _openbsd || _netbsd) {
141
- if (typeof pathToIp === 'undefined') {
142
- try {
143
- const lines = execSync('which ip', util.execOptsLinux).toString().split('\n');
144
- if (lines.length && lines[0].indexOf(':') === -1 && lines[0].indexOf('/') === 0) {
145
- pathToIp = lines[0];
146
- } else {
147
- pathToIp = '';
148
- }
149
- } catch {
150
- pathToIp = '';
151
- }
152
- }
153
- try {
154
- const cmd = 'export LC_ALL=C; ' + (pathToIp ? pathToIp + ' link show up' : '/sbin/ifconfig') + '; unset LC_ALL';
155
- const res = execSync(cmd, util.execOptsLinux);
156
- const lines = res.toString().split('\n');
157
- for (let i = 0; i < lines.length; i++) {
158
- if (lines[i] && lines[i][0] !== ' ') {
159
- if (pathToIp) {
160
- const nextline = lines[i + 1].trim().split(' ');
161
- if (nextline[0] === 'link/ether') {
162
- iface = lines[i].split(' ')[1];
163
- iface = iface.slice(0, iface.length - 1);
164
- mac = nextline[1];
165
- }
166
- } else {
167
- iface = lines[i].split(' ')[0];
168
- mac = lines[i].split('HWaddr ')[1];
169
- }
170
-
171
- if (iface && mac) {
172
- result[iface] = mac.trim();
173
- iface = '';
174
- mac = '';
175
- }
176
- }
177
- }
178
- } catch {
179
- util.noop();
180
- }
181
- }
182
- if (_darwin) {
183
- try {
184
- const cmd = '/sbin/ifconfig';
185
- const res = execSync(cmd);
186
- const lines = res.toString().split('\n');
187
- for (let i = 0; i < lines.length; i++) {
188
- if (lines[i] && lines[i][0] !== '\t' && lines[i].indexOf(':') > 0) {
189
- iface = lines[i].split(':')[0];
190
- } else if (lines[i].indexOf('\tether ') === 0) {
191
- mac = lines[i].split('\tether ')[1];
192
- if (iface && mac) {
193
- result[iface] = mac.trim();
194
- iface = '';
195
- mac = '';
196
- }
197
- }
198
- }
199
- } catch {
200
- util.noop();
201
- }
202
- }
203
- return result;
204
- }
205
-
206
- function networkInterfaceDefault(callback) {
207
- return new Promise((resolve) => {
208
- process.nextTick(() => {
209
- const result = getDefaultNetworkInterface();
210
- if (callback) {
211
- callback(result);
212
- }
213
- resolve(result);
214
- });
215
- });
216
- }
217
-
218
- exports.networkInterfaceDefault = networkInterfaceDefault;
219
-
220
- // --------------------------
221
- // NET - interfaces
222
-
223
- function parseLinesWindowsNics(sections, nconfigsections) {
224
- const nics = [];
225
- for (let i in sections) {
226
- try {
227
- if ({}.hasOwnProperty.call(sections, i)) {
228
- if (sections[i].trim() !== '') {
229
- const lines = sections[i].trim().split('\r\n');
230
- let linesNicConfig = null;
231
- try {
232
- linesNicConfig = nconfigsections && nconfigsections[i] ? nconfigsections[i].trim().split('\r\n') : [];
233
- } catch {
234
- util.noop();
235
- }
236
- const netEnabled = util.getValue(lines, 'NetEnabled', ':');
237
- let adapterType = util.getValue(lines, 'AdapterTypeID', ':') === '9' ? 'wireless' : 'wired';
238
- const ifacename = util.getValue(lines, 'Name', ':').replace(/\]/g, ')').replace(/\[/g, '(');
239
- const iface = util.getValue(lines, 'NetConnectionID', ':').replace(/\]/g, ')').replace(/\[/g, '(');
240
- if (ifacename.toLowerCase().indexOf('wi-fi') >= 0 || ifacename.toLowerCase().indexOf('wireless') >= 0) {
241
- adapterType = 'wireless';
242
- }
243
- if (netEnabled !== '') {
244
- const speed = parseInt(util.getValue(lines, 'speed', ':').trim(), 10) / 1000000;
245
- nics.push({
246
- mac: util.getValue(lines, 'MACAddress', ':').toLowerCase(),
247
- dhcp: util.getValue(linesNicConfig, 'dhcpEnabled', ':').toLowerCase() === 'true',
248
- name: ifacename,
249
- iface,
250
- netEnabled: netEnabled === 'TRUE',
251
- speed: isNaN(speed) ? null : speed,
252
- operstate: util.getValue(lines, 'NetConnectionStatus', ':') === '2' ? 'up' : 'down',
253
- type: adapterType
254
- });
255
- }
256
- }
257
- }
258
- } catch {
259
- util.noop();
260
- }
261
- }
262
- return nics;
263
- }
264
-
265
- function getWindowsNics() {
266
- return new Promise((resolve) => {
267
- process.nextTick(() => {
268
- let cmd = 'Get-CimInstance Win32_NetworkAdapter | fl *' + "; echo '#-#-#-#';";
269
- cmd += 'Get-CimInstance Win32_NetworkAdapterConfiguration | fl DHCPEnabled' + '';
270
- try {
271
- util.powerShell(cmd).then((data) => {
272
- data = data.split('#-#-#-#');
273
- const nsections = (data[0] || '').split(/\n\s*\n/);
274
- const nconfigsections = (data[1] || '').split(/\n\s*\n/);
275
- resolve(parseLinesWindowsNics(nsections, nconfigsections));
276
- });
277
- } catch {
278
- resolve([]);
279
- }
280
- });
281
- });
282
- }
283
-
284
- function getWindowsDNSsuffixes() {
285
- let iface = {};
286
-
287
- const dnsSuffixes = {
288
- primaryDNS: '',
289
- exitCode: 0,
290
- ifaces: []
291
- };
292
-
293
- try {
294
- const ipconfig = execSync('ipconfig /all', util.execOptsWin);
295
- const ipconfigArray = ipconfig.split('\r\n\r\n');
296
-
297
- ipconfigArray.forEach((element, index) => {
298
- if (index === 1) {
299
- const longPrimaryDNS = element.split('\r\n').filter((element) => {
300
- return element.toUpperCase().includes('DNS');
301
- });
302
- const primaryDNS = longPrimaryDNS[0].substring(longPrimaryDNS[0].lastIndexOf(':') + 1);
303
- dnsSuffixes.primaryDNS = primaryDNS.trim();
304
- if (!dnsSuffixes.primaryDNS) {
305
- dnsSuffixes.primaryDNS = 'Not defined';
306
- }
307
- }
308
- if (index > 1) {
309
- if (index % 2 === 0) {
310
- const name = element.substring(element.lastIndexOf(' ') + 1).replace(':', '');
311
- iface.name = name;
312
- } else {
313
- const connectionSpecificDNS = element.split('\r\n').filter((element) => {
314
- return element.toUpperCase().includes('DNS');
315
- });
316
- const dnsSuffix = connectionSpecificDNS[0].substring(connectionSpecificDNS[0].lastIndexOf(':') + 1);
317
- iface.dnsSuffix = dnsSuffix.trim();
318
- dnsSuffixes.ifaces.push(iface);
319
- iface = {};
320
- }
321
- }
322
- });
323
-
324
- return dnsSuffixes;
325
- } catch {
326
- return {
327
- primaryDNS: '',
328
- exitCode: 0,
329
- ifaces: []
330
- };
331
- }
332
- }
333
-
334
- function getWindowsIfaceDNSsuffix(ifaces, ifacename) {
335
- let dnsSuffix = '';
336
- // Adding (.) to ensure ifacename compatibility when duplicated iface-names
337
- const interfaceName = ifacename + '.';
338
- try {
339
- const connectionDnsSuffix = ifaces
340
- .filter((iface) => {
341
- return interfaceName.includes(iface.name + '.');
342
- })
343
- .map((iface) => iface.dnsSuffix);
344
- if (connectionDnsSuffix[0]) {
345
- dnsSuffix = connectionDnsSuffix[0];
346
- }
347
- if (!dnsSuffix) {
348
- dnsSuffix = '';
349
- }
350
- return dnsSuffix;
351
- } catch {
352
- return 'Unknown';
353
- }
354
- }
355
-
356
- function getWindowsWiredProfilesInformation() {
357
- try {
358
- const result = execSync('netsh lan show profiles', util.execOptsWin);
359
- const profileList = result.split('\r\nProfile on interface');
360
- return profileList;
361
- } catch (error) {
362
- if (error.status === 1 && error.stdout.includes('AutoConfig')) {
363
- return 'Disabled';
364
- }
365
- return [];
366
- }
367
- }
368
-
369
- function getWindowsWirelessIfaceSSID(interfaceName) {
370
- try {
371
- const result = execSync(`netsh wlan show interface name="${interfaceName}" | findstr "SSID"`, util.execOptsWin);
372
- const SSID = result.split('\r\n').shift();
373
- const parseSSID = SSID.split(':').pop().trim();
374
- return parseSSID;
375
- } catch {
376
- return 'Unknown';
377
- }
378
- }
379
- function getWindowsIEEE8021x(connectionType, iface, ifaces) {
380
- const i8021x = {
381
- state: 'Unknown',
382
- protocol: 'Unknown'
383
- };
384
-
385
- if (ifaces === 'Disabled') {
386
- i8021x.state = 'Disabled';
387
- i8021x.protocol = 'Not defined';
388
- return i8021x;
389
- }
390
-
391
- if (connectionType === 'wired' && ifaces.length > 0) {
392
- try {
393
- // Get 802.1x information by interface name
394
- const iface8021xInfo = ifaces.find((element) => {
395
- return element.includes(iface + '\r\n');
396
- });
397
- const arrayIface8021xInfo = iface8021xInfo.split('\r\n');
398
- const state8021x = arrayIface8021xInfo.find((element) => {
399
- return element.includes('802.1x');
400
- });
401
-
402
- if (state8021x.includes('Disabled')) {
403
- i8021x.state = 'Disabled';
404
- i8021x.protocol = 'Not defined';
405
- } else if (state8021x.includes('Enabled')) {
406
- const protocol8021x = arrayIface8021xInfo.find((element) => {
407
- return element.includes('EAP');
408
- });
409
- i8021x.protocol = protocol8021x.split(':').pop();
410
- i8021x.state = 'Enabled';
411
- }
412
- } catch {
413
- return i8021x;
414
- }
415
- } else if (connectionType === 'wireless') {
416
- let i8021xState = '';
417
- let i8021xProtocol = '';
418
-
419
- try {
420
- const SSID = getWindowsWirelessIfaceSSID(iface);
421
- if (SSID !== 'Unknown') {
422
- const ifaceSanitized = util.sanitizeString(SSID);
423
- const profiles = execSync(`netsh wlan show profiles "${ifaceSanitized}"`, util.execOptsWin).split('\r\n');
424
- i8021xState = (profiles.find((l) => l.indexOf('802.1X') >= 0) || '').trim();
425
- i8021xProtocol = (profiles.find((l) => l.indexOf('EAP') >= 0) || '').trim();
426
- }
427
-
428
- if (i8021xState.includes(':') && i8021xProtocol.includes(':')) {
429
- i8021x.state = i8021xState.split(':').pop();
430
- i8021x.protocol = i8021xProtocol.split(':').pop();
431
- }
432
- } catch (error) {
433
- if (error.status === 1 && error.stdout.includes('AutoConfig')) {
434
- i8021x.state = 'Disabled';
435
- i8021x.protocol = 'Not defined';
436
- }
437
- return i8021x;
438
- }
439
- }
440
-
441
- return i8021x;
442
- }
443
-
444
- function splitSectionsNics(lines) {
445
- const result = [];
446
- let section = [];
447
- lines.forEach((line) => {
448
- if (!line.startsWith('\t') && !line.startsWith(' ')) {
449
- if (section.length) {
450
- result.push(section);
451
- section = [];
452
- }
453
- }
454
- section.push(line);
455
- });
456
- if (section.length) {
457
- result.push(section);
458
- }
459
- return result;
460
- }
461
-
462
- function parseLinesDarwinNics(sections) {
463
- const nics = [];
464
- sections.forEach((section) => {
465
- const nic = {
466
- iface: '',
467
- mtu: null,
468
- mac: '',
469
- ip6: '',
470
- ip4: '',
471
- speed: null,
472
- type: '',
473
- operstate: '',
474
- duplex: '',
475
- internal: false
476
- };
477
- const first = section[0];
478
- nic.iface = first.split(':')[0].trim();
479
- const parts = first.split('> mtu');
480
- nic.mtu = parts.length > 1 ? parseInt(parts[1], 10) : null;
481
- if (isNaN(nic.mtu)) {
482
- nic.mtu = null;
483
- }
484
- nic.internal = parts[0].toLowerCase().indexOf('loopback') > -1;
485
- section.forEach((line) => {
486
- if (line.trim().startsWith('ether ')) {
487
- nic.mac = line.split('ether ')[1].toLowerCase().trim();
488
- }
489
- if (line.trim().startsWith('inet6 ') && !nic.ip6) {
490
- nic.ip6 = line.split('inet6 ')[1].toLowerCase().split('%')[0].split(' ')[0];
491
- }
492
- if (line.trim().startsWith('inet ') && !nic.ip4) {
493
- nic.ip4 = line.split('inet ')[1].toLowerCase().split(' ')[0];
494
- }
495
- });
496
- let speed = util.getValue(section, 'link rate');
497
- nic.speed = speed ? parseFloat(speed) : null;
498
- if (nic.speed === null) {
499
- speed = util.getValue(section, 'uplink rate');
500
- nic.speed = speed ? parseFloat(speed) : null;
501
- if (nic.speed !== null && speed.toLowerCase().indexOf('gbps') >= 0) {
502
- nic.speed = nic.speed * 1000;
503
- }
504
- } else {
505
- if (speed.toLowerCase().indexOf('gbps') >= 0) {
506
- nic.speed = nic.speed * 1000;
507
- }
508
- }
509
- nic.type = util.getValue(section, 'type').toLowerCase().indexOf('wi-fi') > -1 ? 'wireless' : 'wired';
510
- const operstate = util.getValue(section, 'status').toLowerCase();
511
- nic.operstate = operstate === 'active' ? 'up' : operstate === 'inactive' ? 'down' : 'unknown';
512
- nic.duplex = util.getValue(section, 'media').toLowerCase().indexOf('half-duplex') > -1 ? 'half' : 'full';
513
- if (nic.ip6 || nic.ip4 || nic.mac) {
514
- nics.push(nic);
515
- }
516
- });
517
- return nics;
518
- }
519
-
520
- function getDarwinNics() {
521
- const cmd = '/sbin/ifconfig -v';
522
- try {
523
- const lines = execSync(cmd, { maxBuffer: 1024 * 102400 })
524
- .toString()
525
- .split('\n');
526
- const nsections = splitSectionsNics(lines);
527
- return parseLinesDarwinNics(nsections);
528
- } catch {
529
- return [];
530
- }
531
- }
532
-
533
- function getLinuxIfaceConnectionName(interfaceName) {
534
- try {
535
- const output = execFileSync('nmcli', ['device', 'status'], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
536
- const result = util.grep(output, interfaceName);
537
-
538
- const resultFormat = result.replace(/\s+/g, ' ').trim();
539
- const connectionNameLines = resultFormat.split(' ').slice(3);
540
- const connectionName = connectionNameLines.join(' ');
541
- const connectionNameSanitized = util.sanitizeString(connectionName, false);
542
-
543
- return connectionNameSanitized !== '--' ? connectionNameSanitized : '';
544
- } catch {
545
- return '';
546
- }
547
- }
548
-
549
- function checkLinuxDCHPInterfaces(file, depth) {
550
- let result = [];
551
- depth = depth || 0;
552
- if (depth > 10) {
553
- return result;
554
- }
555
- try {
556
- const content = readFileSync(file, { encoding: 'utf8' });
557
- const lines = content.split('\n').filter((l) => /iface|source/.test(l));
558
-
559
- lines.forEach((line) => {
560
- const parts = line.replace(/\s+/g, ' ').trim().split(' ');
561
- if (parts.length >= 4) {
562
- if (line.toLowerCase().indexOf(' inet ') >= 0 && line.toLowerCase().indexOf('dhcp') >= 0) {
563
- result.push(parts[1]);
564
- }
565
- }
566
- if (line.toLowerCase().includes('source')) {
567
- const file = line.split(' ')[1];
568
- result = result.concat(checkLinuxDCHPInterfaces(file, depth + 1));
569
- }
570
- });
571
- } catch {
572
- util.noop();
573
- }
574
- return result;
575
- }
576
-
577
- function getLinuxDHCPNics() {
578
- // alternate methods getting interfaces using DHCP
579
- const cmd = 'ip a 2> /dev/null';
580
- let result = [];
581
- try {
582
- const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
583
- const nsections = splitSectionsNics(lines);
584
- result = parseLinuxDHCPNics(nsections);
585
- } catch {
586
- util.noop();
587
- }
588
- try {
589
- result = checkLinuxDCHPInterfaces('/etc/network/interfaces');
590
- } catch {
591
- util.noop();
592
- }
593
- return result;
594
- }
595
-
596
- function parseLinuxDHCPNics(sections) {
597
- const result = [];
598
- if (sections && sections.length) {
599
- sections.forEach((lines) => {
600
- if (lines && lines.length) {
601
- const parts = lines[0].split(':');
602
- if (parts.length > 2) {
603
- for (let line of lines) {
604
- if (line.indexOf(' inet ') >= 0 && line.indexOf(' dynamic ') >= 0) {
605
- const parts2 = line.split(' ');
606
- const nic = parts2[parts2.length - 1].trim();
607
- result.push(nic);
608
- break;
609
- }
610
- }
611
- }
612
- }
613
- });
614
- }
615
- return result;
616
- }
617
-
618
- function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
619
- let result = false;
620
- if (connectionName) {
621
- try {
622
- const output = execFileSync('nmcli', ['connection', 'show', connectionName], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
623
- const lines = util.grep(output, 'ipv4.method');
624
- const resultFormat = lines.replace(/\s+/g, ' ').trim();
625
-
626
- const dhcStatus = resultFormat.split(' ').slice(1).toString();
627
- switch (dhcStatus) {
628
- case 'auto':
629
- result = true;
630
- break;
631
-
632
- default:
633
- result = false;
634
- break;
635
- }
636
- return result;
637
- } catch {
638
- return DHCPNics.indexOf(iface) >= 0;
639
- }
640
- } else {
641
- return DHCPNics.indexOf(iface) >= 0;
642
- }
643
- }
644
-
645
- function getDarwinIfaceDHCPstatus(iface) {
646
- let result = false;
647
-
648
- try {
649
- const output = execFileSync('ipconfig', ['getpacket', iface], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
650
- const lines = util.grep(output, 'lease_time');
651
- if (lines.length && lines[0].startsWith('lease_time')) {
652
- result = true;
653
- }
654
- } catch {
655
- util.noop();
656
- }
657
- return result;
658
- }
659
-
660
- function getLinuxIfaceDNSsuffix(connectionName) {
661
- if (connectionName) {
662
- try {
663
- const output = execFileSync('nmcli', ['connection', 'show', connectionName], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
664
- const result = util.grep(output, 'ipv4.dns-search');
665
- const resultFormat = result.replace(/\s+/g, ' ').trim();
666
- const dnsSuffix = resultFormat.split(' ').slice(1).toString();
667
- return dnsSuffix === '--' ? 'Not defined' : dnsSuffix;
668
- } catch {
669
- return 'Unknown';
670
- }
671
- } else {
672
- return 'Unknown';
673
- }
674
- }
675
-
676
- function getLinuxIfaceIEEE8021xAuth(connectionName) {
677
- if (connectionName) {
678
- try {
679
- const output = execFileSync('nmcli', ['connection', 'show', connectionName], { ...util.execOptsLinux, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
680
- const result = util.grep(output, '802-1x.eap');
681
- const resultFormat = result.replace(/\s+/g, ' ').trim();
682
- const authenticationProtocol = resultFormat.split(' ').slice(1).toString();
683
-
684
- return authenticationProtocol === '--' ? '' : authenticationProtocol;
685
- } catch {
686
- return 'Not defined';
687
- }
688
- } else {
689
- return 'Not defined';
690
- }
691
- }
692
-
693
- function getLinuxIfaceIEEE8021xState(authenticationProtocol) {
694
- if (authenticationProtocol) {
695
- if (authenticationProtocol === 'Not defined') {
696
- return 'Disabled';
697
- }
698
- return 'Enabled';
699
- } else {
700
- return 'Unknown';
701
- }
702
- }
703
-
704
- function testVirtualNic(iface, ifaceName, mac) {
705
- const virtualMacs = [
706
- '00:00:00:00:00:00',
707
- '00:03:FF',
708
- '00:05:69',
709
- '00:0C:29',
710
- '00:0F:4B',
711
- '00:13:07',
712
- '00:13:BE',
713
- '00:15:5d',
714
- '00:16:3E',
715
- '00:1C:42',
716
- '00:21:F6',
717
- '00:24:0B',
718
- '00:50:56',
719
- '00:A0:B1',
720
- '00:E0:C8',
721
- '08:00:27',
722
- '0A:00:27',
723
- '18:92:2C',
724
- '16:DF:49',
725
- '3C:F3:92',
726
- '54:52:00',
727
- 'FC:15:97'
728
- ];
729
- if (mac) {
730
- return (
731
- virtualMacs.filter((item) => {
732
- return mac.toUpperCase().toUpperCase().startsWith(item.substring(0, mac.length));
733
- }).length > 0 ||
734
- iface.toLowerCase().indexOf(' virtual ') > -1 ||
735
- ifaceName.toLowerCase().indexOf(' virtual ') > -1 ||
736
- iface.toLowerCase().indexOf('vethernet ') > -1 ||
737
- ifaceName.toLowerCase().indexOf('vethernet ') > -1 ||
738
- iface.toLowerCase().startsWith('veth') ||
739
- ifaceName.toLowerCase().startsWith('veth') ||
740
- iface.toLowerCase().startsWith('vboxnet') ||
741
- ifaceName.toLowerCase().startsWith('vboxnet')
742
- );
743
- } else {
744
- return false;
745
- }
746
- }
747
-
748
- function networkInterfaces(callback, rescan, defaultString) {
749
- if (typeof callback === 'string') {
750
- defaultString = callback;
751
- rescan = true;
752
- callback = null;
753
- }
754
-
755
- if (typeof callback === 'boolean') {
756
- rescan = callback;
757
- callback = null;
758
- defaultString = '';
759
- }
760
- if (typeof rescan === 'undefined') {
761
- rescan = true;
762
- }
763
- defaultString = defaultString || '';
764
- defaultString = '' + defaultString;
765
-
766
- return new Promise((resolve) => {
767
- process.nextTick(() => {
768
- const ifaces = os.networkInterfaces();
769
-
770
- let result = [];
771
- let nics = [];
772
- let dnsSuffixes = [];
773
- let nics8021xInfo = [];
774
- // seperate handling in OSX
775
- if (_darwin || _freebsd || _openbsd || _netbsd) {
776
- if (JSON.stringify(ifaces) === JSON.stringify(_ifaces) && !rescan) {
777
- // no changes - just return object
778
- result = _networkInterfaces;
779
-
780
- if (callback) {
781
- callback(result);
782
- }
783
- resolve(result);
784
- } else {
785
- const defaultInterface = getDefaultNetworkInterface();
786
- _ifaces = JSON.parse(JSON.stringify(ifaces));
787
-
788
- nics = getDarwinNics();
789
-
790
- nics.forEach((nic) => {
791
- let ip4link = '';
792
- let ip4linksubnet = '';
793
- let ip6link = '';
794
- let ip6linksubnet = '';
795
- nic.ip4 = '';
796
- nic.ip6 = '';
797
- if ({}.hasOwnProperty.call(ifaces, nic.iface)) {
798
- ifaces[nic.iface].forEach((details) => {
799
- if (details.family === 'IPv4' || details.family === 4) {
800
- if (!nic.ip4 && !nic.ip4.match(/^169.254/i)) {
801
- nic.ip4 = details.address;
802
- nic.ip4subnet = details.netmask;
803
- }
804
- if (nic.ip4.match(/^169.254/i)) {
805
- ip4link = details.address;
806
- ip4linksubnet = details.netmask;
807
- }
808
- }
809
- if (details.family === 'IPv6' || details.family === 6) {
810
- if (!nic.ip6 && !nic.ip6.match(/^fe80::/i)) {
811
- nic.ip6 = details.address;
812
- nic.ip6subnet = details.netmask;
813
- }
814
- if (nic.ip6.match(/^fe80::/i)) {
815
- ip6link = details.address;
816
- ip6linksubnet = details.netmask;
817
- }
818
- }
819
- });
820
- }
821
- if (!nic.ip4 && ip4link) {
822
- nic.ip4 = ip4link;
823
- nic.ip4subnet = ip4linksubnet;
824
- }
825
- if (!nic.ip6 && ip6link) {
826
- nic.ip6 = ip6link;
827
- nic.ip6subnet = ip6linksubnet;
828
- }
829
-
830
- const ifaceSanitized = util.sanitizeString(nic.iface);
831
-
832
- result.push({
833
- iface: nic.iface,
834
- ifaceName: nic.iface,
835
- default: nic.iface === defaultInterface,
836
- ip4: nic.ip4,
837
- ip4subnet: nic.ip4subnet || '',
838
- ip6: nic.ip6,
839
- ip6subnet: nic.ip6subnet || '',
840
- mac: nic.mac,
841
- internal: nic.internal,
842
- virtual: nic.internal ? false : testVirtualNic(nic.iface, nic.iface, nic.mac),
843
- operstate: nic.operstate,
844
- type: nic.type,
845
- duplex: nic.duplex,
846
- mtu: nic.mtu,
847
- speed: nic.speed,
848
- dhcp: getDarwinIfaceDHCPstatus(ifaceSanitized),
849
- dnsSuffix: '',
850
- ieee8021xAuth: '',
851
- ieee8021xState: '',
852
- carrierChanges: 0
853
- });
854
- });
855
- _networkInterfaces = result;
856
- if (defaultString.toLowerCase().indexOf('default') >= 0) {
857
- result = result.filter((item) => item.default);
858
- if (result.length > 0) {
859
- result = result[0];
860
- } else {
861
- result = [];
862
- }
863
- }
864
- if (callback) {
865
- callback(result);
866
- }
867
- resolve(result);
868
- }
869
- }
870
- if (_linux) {
871
- if (JSON.stringify(ifaces) === JSON.stringify(_ifaces) && !rescan) {
872
- // no changes - just return object
873
- result = _networkInterfaces;
874
-
875
- if (callback) {
876
- callback(result);
877
- }
878
- resolve(result);
879
- } else {
880
- _ifaces = JSON.parse(JSON.stringify(ifaces));
881
- _dhcpNics = getLinuxDHCPNics();
882
- const defaultInterface = getDefaultNetworkInterface();
883
- for (let dev in ifaces) {
884
- let ip4 = '';
885
- let ip4subnet = '';
886
- let ip6 = '';
887
- let ip6subnet = '';
888
- let mac = '';
889
- let duplex = '';
890
- let mtu = '';
891
- let speed = null;
892
- let carrierChanges = 0;
893
- let dhcp = false;
894
- let dnsSuffix = '';
895
- let ieee8021xAuth = '';
896
- let ieee8021xState = '';
897
- let type = '';
898
-
899
- let ip4link = '';
900
- let ip4linksubnet = '';
901
- let ip6link = '';
902
- let ip6linksubnet = '';
903
-
904
- if ({}.hasOwnProperty.call(ifaces, dev)) {
905
- const ifaceName = dev;
906
- ifaces[dev].forEach((details) => {
907
- if (details.family === 'IPv4' || details.family === 4) {
908
- if (!ip4 && !ip4.match(/^169.254/i)) {
909
- ip4 = details.address;
910
- ip4subnet = details.netmask;
911
- }
912
- if (ip4.match(/^169.254/i)) {
913
- ip4link = details.address;
914
- ip4linksubnet = details.netmask;
915
- }
916
- }
917
- if (details.family === 'IPv6' || details.family === 6) {
918
- if (!ip6 && !ip6.match(/^fe80::/i)) {
919
- ip6 = details.address;
920
- ip6subnet = details.netmask;
921
- }
922
- if (ip6.match(/^fe80::/i)) {
923
- ip6link = details.address;
924
- ip6linksubnet = details.netmask;
925
- }
926
- }
927
- mac = details.mac;
928
- // fallback due to https://github.com/nodejs/node/issues/13581 (node 8.1 - node 8.2)
929
- const nodeMainVersion = parseInt(process.versions.node.split('.'), 10);
930
- if (mac.indexOf('00:00:0') > -1 && (_linux || _darwin) && !details.internal && nodeMainVersion >= 8 && nodeMainVersion <= 11) {
931
- if (Object.keys(_mac).length === 0) {
932
- _mac = getMacAddresses();
933
- }
934
- mac = _mac[dev] || '';
935
- }
936
- });
937
- if (!ip4 && ip4link) {
938
- ip4 = ip4link;
939
- ip4subnet = ip4linksubnet;
940
- }
941
- if (!ip6 && ip6link) {
942
- ip6 = ip6link;
943
- ip6subnet = ip6linksubnet;
944
- }
945
- const iface = dev.split(':')[0].trim();
946
- const ifaceSanitized = util.sanitizeString(iface);
947
- const cmd = `echo -n "addr_assign_type: "; cat /sys/class/net/${ifaceSanitized}/addr_assign_type 2>/dev/null; echo;
948
- echo -n "address: "; cat /sys/class/net/${ifaceSanitized}/address 2>/dev/null; echo;
949
- echo -n "addr_len: "; cat /sys/class/net/${ifaceSanitized}/addr_len 2>/dev/null; echo;
950
- echo -n "broadcast: "; cat /sys/class/net/${ifaceSanitized}/broadcast 2>/dev/null; echo;
951
- echo -n "carrier: "; cat /sys/class/net/${ifaceSanitized}/carrier 2>/dev/null; echo;
952
- echo -n "carrier_changes: "; cat /sys/class/net/${ifaceSanitized}/carrier_changes 2>/dev/null; echo;
953
- echo -n "dev_id: "; cat /sys/class/net/${ifaceSanitized}/dev_id 2>/dev/null; echo;
954
- echo -n "dev_port: "; cat /sys/class/net/${ifaceSanitized}/dev_port 2>/dev/null; echo;
955
- echo -n "dormant: "; cat /sys/class/net/${ifaceSanitized}/dormant 2>/dev/null; echo;
956
- echo -n "duplex: "; cat /sys/class/net/${ifaceSanitized}/duplex 2>/dev/null; echo;
957
- echo -n "flags: "; cat /sys/class/net/${ifaceSanitized}/flags 2>/dev/null; echo;
958
- echo -n "gro_flush_timeout: "; cat /sys/class/net/${ifaceSanitized}/gro_flush_timeout 2>/dev/null; echo;
959
- echo -n "ifalias: "; cat /sys/class/net/${ifaceSanitized}/ifalias 2>/dev/null; echo;
960
- echo -n "ifindex: "; cat /sys/class/net/${ifaceSanitized}/ifindex 2>/dev/null; echo;
961
- echo -n "iflink: "; cat /sys/class/net/${ifaceSanitized}/iflink 2>/dev/null; echo;
962
- echo -n "link_mode: "; cat /sys/class/net/${ifaceSanitized}/link_mode 2>/dev/null; echo;
963
- echo -n "mtu: "; cat /sys/class/net/${ifaceSanitized}/mtu 2>/dev/null; echo;
964
- echo -n "netdev_group: "; cat /sys/class/net/${ifaceSanitized}/netdev_group 2>/dev/null; echo;
965
- echo -n "operstate: "; cat /sys/class/net/${ifaceSanitized}/operstate 2>/dev/null; echo;
966
- echo -n "proto_down: "; cat /sys/class/net/${ifaceSanitized}/proto_down 2>/dev/null; echo;
967
- echo -n "speed: "; cat /sys/class/net/${ifaceSanitized}/speed 2>/dev/null; echo;
968
- echo -n "tx_queue_len: "; cat /sys/class/net/${ifaceSanitized}/tx_queue_len 2>/dev/null; echo;
969
- echo -n "type: "; cat /sys/class/net/${ifaceSanitized}/type 2>/dev/null; echo;
970
- echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null | grep ${ifaceSanitized}; echo;
971
- echo -n "wirelessspeed: "; iw dev ${ifaceSanitized} link 2>&1 | grep bitrate; echo;`;
972
-
973
- let lines = [];
974
- try {
975
- lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
976
- const connectionName = getLinuxIfaceConnectionName(ifaceSanitized);
977
- dhcp = getLinuxIfaceDHCPstatus(ifaceSanitized, connectionName, _dhcpNics);
978
- dnsSuffix = getLinuxIfaceDNSsuffix(connectionName);
979
- ieee8021xAuth = getLinuxIfaceIEEE8021xAuth(connectionName);
980
- ieee8021xState = getLinuxIfaceIEEE8021xState(ieee8021xAuth);
981
- } catch {
982
- util.noop();
983
- }
984
- duplex = util.getValue(lines, 'duplex');
985
- duplex = duplex.startsWith('cat') ? '' : duplex;
986
- mtu = parseInt(util.getValue(lines, 'mtu'), 10);
987
- let myspeed = parseInt(util.getValue(lines, 'speed'), 10);
988
- speed = isNaN(myspeed) ? null : myspeed;
989
- const wirelessspeed = util.getValue(lines, 'tx bitrate');
990
- if (speed === null && wirelessspeed) {
991
- myspeed = parseFloat(wirelessspeed);
992
- speed = isNaN(myspeed) ? null : myspeed;
993
- }
994
- carrierChanges = parseInt(util.getValue(lines, 'carrier_changes'), 10);
995
- const operstate = util.getValue(lines, 'operstate');
996
- type = operstate === 'up' ? (util.getValue(lines, 'wireless').trim() ? 'wireless' : 'wired') : 'unknown';
997
- if (ifaceSanitized === 'lo' || ifaceSanitized.startsWith('bond')) {
998
- type = 'virtual';
999
- }
1000
-
1001
- let internal = ifaces[dev] && ifaces[dev][0] ? ifaces[dev][0].internal : false;
1002
- if (dev.toLowerCase().indexOf('loopback') > -1 || ifaceName.toLowerCase().indexOf('loopback') > -1) {
1003
- internal = true;
1004
- }
1005
- const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac);
1006
- result.push({
1007
- iface: ifaceSanitized,
1008
- ifaceName,
1009
- default: iface === defaultInterface,
1010
- ip4,
1011
- ip4subnet,
1012
- ip6,
1013
- ip6subnet,
1014
- mac,
1015
- internal,
1016
- virtual,
1017
- operstate,
1018
- type,
1019
- duplex,
1020
- mtu,
1021
- speed,
1022
- dhcp,
1023
- dnsSuffix,
1024
- ieee8021xAuth,
1025
- ieee8021xState,
1026
- carrierChanges
1027
- });
1028
- }
1029
- }
1030
- _networkInterfaces = result;
1031
- if (defaultString.toLowerCase().indexOf('default') >= 0) {
1032
- result = result.filter((item) => item.default);
1033
- if (result.length > 0) {
1034
- result = result[0];
1035
- } else {
1036
- result = [];
1037
- }
1038
- }
1039
- if (callback) {
1040
- callback(result);
1041
- }
1042
- resolve(result);
1043
- }
1044
- }
1045
- if (_windows) {
1046
- if (JSON.stringify(ifaces) === JSON.stringify(_ifaces) && !rescan) {
1047
- // no changes - just return object
1048
- result = _networkInterfaces;
1049
-
1050
- if (callback) {
1051
- callback(result);
1052
- }
1053
- resolve(result);
1054
- } else {
1055
- _ifaces = JSON.parse(JSON.stringify(ifaces));
1056
- const defaultInterface = getDefaultNetworkInterface();
1057
-
1058
- getWindowsNics().then((nics) => {
1059
- nics.forEach((nic) => {
1060
- let found = false;
1061
- Object.keys(ifaces).forEach((key) => {
1062
- if (!found) {
1063
- ifaces[key].forEach((value) => {
1064
- if (Object.keys(value).indexOf('mac') >= 0) {
1065
- found = value['mac'] === nic.mac;
1066
- }
1067
- });
1068
- }
1069
- });
1070
-
1071
- if (!found) {
1072
- ifaces[nic.name] = [{ mac: nic.mac }];
1073
- }
1074
- });
1075
- nics8021xInfo = getWindowsWiredProfilesInformation();
1076
- dnsSuffixes = getWindowsDNSsuffixes();
1077
- for (let dev in ifaces) {
1078
- const ifaceSanitized = util.sanitizeString(dev);
1079
-
1080
- let iface = dev;
1081
- let ip4 = '';
1082
- let ip4subnet = '';
1083
- let ip6 = '';
1084
- let ip6subnet = '';
1085
- let mac = '';
1086
- let duplex = '';
1087
- let mtu = '';
1088
- let speed = null;
1089
- let carrierChanges = 0;
1090
- let operstate = 'down';
1091
- let dhcp = false;
1092
- let dnsSuffix = '';
1093
- let ieee8021xAuth = '';
1094
- let ieee8021xState = '';
1095
- let type = '';
1096
-
1097
- if ({}.hasOwnProperty.call(ifaces, dev)) {
1098
- let ifaceName = dev;
1099
- ifaces[dev].forEach((details) => {
1100
- if (details.family === 'IPv4' || details.family === 4) {
1101
- ip4 = details.address;
1102
- ip4subnet = details.netmask;
1103
- }
1104
- if (details.family === 'IPv6' || details.family === 6) {
1105
- if (!ip6 || ip6.match(/^fe80::/i)) {
1106
- ip6 = details.address;
1107
- ip6subnet = details.netmask;
1108
- }
1109
- }
1110
- mac = details.mac;
1111
- // fallback due to https://github.com/nodejs/node/issues/13581 (node 8.1 - node 8.2)
1112
- const nodeMainVersion = parseInt(process.versions.node.split('.'), 10);
1113
- if (mac.indexOf('00:00:0') > -1 && (_linux || _darwin) && !details.internal && nodeMainVersion >= 8 && nodeMainVersion <= 11) {
1114
- if (Object.keys(_mac).length === 0) {
1115
- _mac = getMacAddresses();
1116
- }
1117
- mac = _mac[dev] || '';
1118
- }
1119
- });
1120
-
1121
- dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, ifaceSanitized);
1122
- let foundFirst = false;
1123
- nics.forEach((detail) => {
1124
- if (detail.mac === mac && !foundFirst) {
1125
- iface = detail.iface || iface;
1126
- ifaceName = detail.name;
1127
- dhcp = detail.dhcp;
1128
- operstate = detail.operstate;
1129
- speed = operstate === 'up' ? detail.speed : 0;
1130
- type = detail.type;
1131
- foundFirst = true;
1132
- }
1133
- });
1134
-
1135
- if (
1136
- dev.toLowerCase().indexOf('wlan') >= 0 ||
1137
- ifaceName.toLowerCase().indexOf('wlan') >= 0 ||
1138
- ifaceName.toLowerCase().indexOf('802.11n') >= 0 ||
1139
- ifaceName.toLowerCase().indexOf('wireless') >= 0 ||
1140
- ifaceName.toLowerCase().indexOf('wi-fi') >= 0 ||
1141
- ifaceName.toLowerCase().indexOf('wifi') >= 0
1142
- ) {
1143
- type = 'wireless';
1144
- }
1145
-
1146
- const IEEE8021x = getWindowsIEEE8021x(type, ifaceSanitized, nics8021xInfo);
1147
- ieee8021xAuth = IEEE8021x.protocol;
1148
- ieee8021xState = IEEE8021x.state;
1149
- let internal = ifaces[dev] && ifaces[dev][0] ? ifaces[dev][0].internal : false;
1150
- if (dev.toLowerCase().indexOf('loopback') > -1 || ifaceName.toLowerCase().indexOf('loopback') > -1) {
1151
- internal = true;
1152
- }
1153
- const virtual = internal ? false : testVirtualNic(dev, ifaceName, mac);
1154
- result.push({
1155
- iface,
1156
- ifaceName,
1157
- default: iface === defaultInterface,
1158
- ip4,
1159
- ip4subnet,
1160
- ip6,
1161
- ip6subnet,
1162
- mac,
1163
- internal,
1164
- virtual,
1165
- operstate,
1166
- type,
1167
- duplex,
1168
- mtu,
1169
- speed,
1170
- dhcp,
1171
- dnsSuffix,
1172
- ieee8021xAuth,
1173
- ieee8021xState,
1174
- carrierChanges
1175
- });
1176
- }
1177
- }
1178
- _networkInterfaces = result;
1179
- if (defaultString.toLowerCase().indexOf('default') >= 0) {
1180
- result = result.filter((item) => item.default);
1181
- if (result.length > 0) {
1182
- result = result[0];
1183
- } else {
1184
- result = [];
1185
- }
1186
- }
1187
- if (callback) {
1188
- callback(result);
1189
- }
1190
- resolve(result);
1191
- });
1192
- }
1193
- }
1194
- });
1195
- });
1196
- }
1197
-
1198
- exports.networkInterfaces = networkInterfaces;
1199
-
1200
- // --------------------------
1201
- // NET - Speed
1202
-
1203
- function calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors) {
1204
- const result = {
1205
- iface,
1206
- operstate,
1207
- rx_bytes,
1208
- rx_dropped,
1209
- rx_errors,
1210
- tx_bytes,
1211
- tx_dropped,
1212
- tx_errors,
1213
- rx_sec: null,
1214
- tx_sec: null,
1215
- ms: 0
1216
- };
1217
-
1218
- if (_network[iface] && _network[iface].ms) {
1219
- result.ms = Date.now() - _network[iface].ms;
1220
- result.rx_sec = rx_bytes - _network[iface].rx_bytes >= 0 ? (rx_bytes - _network[iface].rx_bytes) / (result.ms / 1000) : 0;
1221
- result.tx_sec = tx_bytes - _network[iface].tx_bytes >= 0 ? (tx_bytes - _network[iface].tx_bytes) / (result.ms / 1000) : 0;
1222
- _network[iface].rx_bytes = rx_bytes;
1223
- _network[iface].tx_bytes = tx_bytes;
1224
- _network[iface].rx_sec = result.rx_sec;
1225
- _network[iface].tx_sec = result.tx_sec;
1226
- _network[iface].ms = Date.now();
1227
- _network[iface].last_ms = result.ms;
1228
- _network[iface].operstate = operstate;
1229
- } else {
1230
- if (!_network[iface]) {
1231
- _network[iface] = {};
1232
- }
1233
- _network[iface].rx_bytes = rx_bytes;
1234
- _network[iface].tx_bytes = tx_bytes;
1235
- _network[iface].rx_sec = null;
1236
- _network[iface].tx_sec = null;
1237
- _network[iface].ms = Date.now();
1238
- _network[iface].last_ms = 0;
1239
- _network[iface].operstate = operstate;
1240
- }
1241
- return result;
1242
- }
1243
-
1244
- function networkStats(ifaces, callback) {
1245
- let ifacesArray = [];
1246
-
1247
- return new Promise((resolve) => {
1248
- process.nextTick(() => {
1249
- // fallback - if only callback is given
1250
- if (util.isFunction(ifaces) && !callback) {
1251
- callback = ifaces;
1252
- ifacesArray = [getDefaultNetworkInterface()];
1253
- } else {
1254
- if (typeof ifaces !== 'string' && ifaces !== undefined) {
1255
- if (callback) {
1256
- callback([]);
1257
- }
1258
- return resolve([]);
1259
- }
1260
- ifaces = ifaces || getDefaultNetworkInterface();
1261
-
1262
- try {
1263
- ifaces.__proto__.toLowerCase = util.stringToLower;
1264
- ifaces.__proto__.replace = util.stringReplace;
1265
- ifaces.__proto__.toString = util.stringToString;
1266
- ifaces.__proto__.substr = util.stringSubstr;
1267
- ifaces.__proto__.substring = util.stringSubstring;
1268
- ifaces.__proto__.trim = util.stringTrim;
1269
- ifaces.__proto__.startsWith = util.stringStartWith;
1270
- } catch {
1271
- Object.setPrototypeOf(ifaces, util.stringObj);
1272
- }
1273
-
1274
- ifaces = ifaces.trim().replace(/,+/g, '|');
1275
- ifacesArray = ifaces.split('|');
1276
- }
1277
-
1278
- const result = [];
1279
-
1280
- const workload = [];
1281
- if (ifacesArray.length && ifacesArray[0].trim() === '*') {
1282
- ifacesArray = [];
1283
- networkInterfaces(false).then((allIFaces) => {
1284
- for (let iface of allIFaces) {
1285
- ifacesArray.push(iface.iface);
1286
- }
1287
- networkStats(ifacesArray.join(',')).then((result) => {
1288
- if (callback) {
1289
- callback(result);
1290
- }
1291
- resolve(result);
1292
- });
1293
- });
1294
- } else {
1295
- for (let iface of ifacesArray) {
1296
- workload.push(networkStatsSingle(iface.trim()));
1297
- }
1298
- if (workload.length) {
1299
- Promise.all(workload).then((data) => {
1300
- if (callback) {
1301
- callback(data);
1302
- }
1303
- resolve(data);
1304
- });
1305
- } else {
1306
- if (callback) {
1307
- callback(result);
1308
- }
1309
- resolve(result);
1310
- }
1311
- }
1312
- });
1313
- });
1314
- }
1315
-
1316
- function networkStatsSingle(iface) {
1317
- function parseLinesWindowsPerfData(sections) {
1318
- const perfData = [];
1319
- for (let i in sections) {
1320
- if ({}.hasOwnProperty.call(sections, i)) {
1321
- if (sections[i].trim() !== '') {
1322
- const lines = sections[i].trim().split('\r\n');
1323
- perfData.push({
1324
- name: util.getValue(lines, 'Name', ':').toLowerCase(),
1325
- desc: util
1326
- .getValue(lines, 'InterfaceDescription', ':')
1327
- .replace(/[()[\] ]+/g, '')
1328
- .replace(/#|\//g, '_')
1329
- .toLowerCase(),
1330
- rx_bytes: parseInt(util.getValue(lines, 'ReceivedBytes', ':'), 10),
1331
- rx_errors: parseInt(util.getValue(lines, 'ReceivedPacketErrors', ':'), 10),
1332
- rx_dropped: parseInt(util.getValue(lines, 'ReceivedDiscardedPackets', ':'), 10),
1333
- tx_bytes: parseInt(util.getValue(lines, 'SentBytes', ':'), 10),
1334
- tx_errors: parseInt(util.getValue(lines, 'OutboundPacketErrors', ':'), 10),
1335
- tx_dropped: parseInt(util.getValue(lines, 'OutboundDiscardedPackets', ':'), 10)
1336
- });
1337
- }
1338
- }
1339
- }
1340
- return perfData;
1341
- }
1342
-
1343
- return new Promise((resolve) => {
1344
- process.nextTick(() => {
1345
- const ifaceSanitized = util.sanitizeString(iface, true);
1346
-
1347
- let result = {
1348
- iface: ifaceSanitized,
1349
- operstate: 'unknown',
1350
- rx_bytes: 0,
1351
- rx_dropped: 0,
1352
- rx_errors: 0,
1353
- tx_bytes: 0,
1354
- tx_dropped: 0,
1355
- tx_errors: 0,
1356
- rx_sec: null,
1357
- tx_sec: null,
1358
- ms: 0
1359
- };
1360
-
1361
- let operstate = 'unknown';
1362
- let rx_bytes = 0;
1363
- let tx_bytes = 0;
1364
- let rx_dropped = 0;
1365
- let rx_errors = 0;
1366
- let tx_dropped = 0;
1367
- let tx_errors = 0;
1368
-
1369
- let cmd, lines, stats;
1370
- if (
1371
- !_network[ifaceSanitized] ||
1372
- (_network[ifaceSanitized] && !_network[ifaceSanitized].ms) ||
1373
- (_network[ifaceSanitized] && _network[ifaceSanitized].ms && Date.now() - _network[ifaceSanitized].ms >= 500)
1374
- ) {
1375
- if (_linux) {
1376
- if (fs.existsSync('/sys/class/net/' + ifaceSanitized)) {
1377
- cmd =
1378
- 'cat /sys/class/net/' +
1379
- ifaceSanitized +
1380
- '/operstate; ' +
1381
- 'cat /sys/class/net/' +
1382
- ifaceSanitized +
1383
- '/statistics/rx_bytes; ' +
1384
- 'cat /sys/class/net/' +
1385
- ifaceSanitized +
1386
- '/statistics/tx_bytes; ' +
1387
- 'cat /sys/class/net/' +
1388
- ifaceSanitized +
1389
- '/statistics/rx_dropped; ' +
1390
- 'cat /sys/class/net/' +
1391
- ifaceSanitized +
1392
- '/statistics/rx_errors; ' +
1393
- 'cat /sys/class/net/' +
1394
- ifaceSanitized +
1395
- '/statistics/tx_dropped; ' +
1396
- 'cat /sys/class/net/' +
1397
- ifaceSanitized +
1398
- '/statistics/tx_errors; ';
1399
- exec(cmd, (error, stdout) => {
1400
- if (!error) {
1401
- lines = stdout.toString().split('\n');
1402
- operstate = lines[0].trim();
1403
- rx_bytes = parseInt(lines[1], 10);
1404
- tx_bytes = parseInt(lines[2], 10);
1405
- rx_dropped = parseInt(lines[3], 10);
1406
- rx_errors = parseInt(lines[4], 10);
1407
- tx_dropped = parseInt(lines[5], 10);
1408
- tx_errors = parseInt(lines[6], 10);
1409
-
1410
- result = calcNetworkSpeed(ifaceSanitized, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
1411
- }
1412
- resolve(result);
1413
- });
1414
- } else {
1415
- resolve(result);
1416
- }
1417
- }
1418
- if (_freebsd || _openbsd || _netbsd) {
1419
- cmd = 'netstat -ibndI ' + ifaceSanitized; // lgtm [js/shell-command-constructed-from-input]
1420
- exec(cmd, (error, stdout) => {
1421
- if (!error) {
1422
- lines = stdout.toString().split('\n');
1423
- for (let i = 1; i < lines.length; i++) {
1424
- const line = lines[i].replace(/ +/g, ' ').split(' ');
1425
- if (line && line[0] && line[7] && line[10]) {
1426
- rx_bytes = rx_bytes + parseInt(line[7]);
1427
- if (line[6].trim() !== '-') {
1428
- rx_dropped = rx_dropped + parseInt(line[6]);
1429
- }
1430
- if (line[5].trim() !== '-') {
1431
- rx_errors = rx_errors + parseInt(line[5]);
1432
- }
1433
- tx_bytes = tx_bytes + parseInt(line[10]);
1434
- if (line[12] && line[12].trim() !== '-') {
1435
- tx_dropped = tx_dropped + parseInt(line[12]);
1436
- }
1437
- if (line[9].trim() !== '-') {
1438
- tx_errors = tx_errors + parseInt(line[9]);
1439
- }
1440
- operstate = 'up';
1441
- }
1442
- }
1443
- result = calcNetworkSpeed(ifaceSanitized, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
1444
- }
1445
- resolve(result);
1446
- });
1447
- }
1448
- if (_darwin) {
1449
- cmd = 'ifconfig ' + ifaceSanitized + ' | grep "status"'; // lgtm [js/shell-command-constructed-from-input]
1450
- exec(cmd, (error, stdout) => {
1451
- result.operstate = (stdout.toString().split(':')[1] || '').trim();
1452
- result.operstate = (result.operstate || '').toLowerCase();
1453
- result.operstate = result.operstate === 'active' ? 'up' : result.operstate === 'inactive' ? 'down' : 'unknown';
1454
- cmd = 'netstat -bdnI ' + ifaceSanitized; // lgtm [js/shell-command-constructed-from-input]
1455
- exec(cmd, (error, stdout) => {
1456
- if (!error) {
1457
- lines = stdout.toString().split('\n');
1458
- // if there is less than 2 lines, no information for this interface was found
1459
- if (lines.length > 1 && lines[1].trim() !== '') {
1460
- // skip header line
1461
- // use the second line because it is tied to the NIC instead of the ipv4 or ipv6 address
1462
- stats = lines[1].replace(/ +/g, ' ').split(' ');
1463
- const offset = stats.length > 11 ? 1 : 0;
1464
- rx_bytes = parseInt(stats[offset + 5]);
1465
- rx_dropped = parseInt(stats[offset + 10]);
1466
- rx_errors = parseInt(stats[offset + 4]);
1467
- tx_bytes = parseInt(stats[offset + 8]);
1468
- tx_dropped = parseInt(stats[offset + 10]);
1469
- tx_errors = parseInt(stats[offset + 7]);
1470
- result = calcNetworkSpeed(ifaceSanitized, rx_bytes, tx_bytes, result.operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
1471
- }
1472
- }
1473
- resolve(result);
1474
- });
1475
- });
1476
- }
1477
- if (_windows) {
1478
- let perfData = [];
1479
- let ifaceName = ifaceSanitized;
1480
-
1481
- // Performance Data
1482
- util
1483
- .powerShell(
1484
- 'Get-NetAdapterStatistics | select Name,InterfaceDescription,ReceivedBytes,ReceivedPacketErrors,ReceivedDiscardedPackets,SentBytes,OutboundPacketErrors,OutboundDiscardedPackets | fl'
1485
- )
1486
- .then((stdout, error) => {
1487
- if (!error) {
1488
- const psections = stdout.toString().split(/\n\s*\n/);
1489
- perfData = parseLinesWindowsPerfData(psections);
1490
- }
1491
-
1492
- // Network Interfaces
1493
- networkInterfaces(false).then((interfaces) => {
1494
- // get bytes sent, received from perfData by name
1495
- rx_bytes = 0;
1496
- tx_bytes = 0;
1497
- perfData.forEach((detail) => {
1498
- interfaces.forEach((det) => {
1499
- if (
1500
- (det.iface.toLowerCase() === ifaceSanitized.toLowerCase() ||
1501
- det.mac.toLowerCase() === ifaceSanitized.toLowerCase() ||
1502
- det.ip4.toLowerCase() === ifaceSanitized.toLowerCase() ||
1503
- det.ip6.toLowerCase() === ifaceSanitized.toLowerCase() ||
1504
- det.ifaceName
1505
- .replace(/[()[\] ]+/g, '')
1506
- .replace(/#|\//g, '_')
1507
- .toLowerCase() ===
1508
- ifaceSanitized
1509
- .replace(/[()[\] ]+/g, '')
1510
- .replace('#', '_')
1511
- .toLowerCase()) &&
1512
- (det.iface.toLowerCase() === detail.name ||
1513
- det.ifaceName
1514
- .replace(/[()[\] ]+/g, '')
1515
- .replace(/#|\//g, '_')
1516
- .toLowerCase() === detail.desc)
1517
- ) {
1518
- ifaceName = det.iface;
1519
- rx_bytes = detail.rx_bytes;
1520
- rx_dropped = detail.rx_dropped;
1521
- rx_errors = detail.rx_errors;
1522
- tx_bytes = detail.tx_bytes;
1523
- tx_dropped = detail.tx_dropped;
1524
- tx_errors = detail.tx_errors;
1525
- operstate = det.operstate;
1526
- }
1527
- });
1528
- });
1529
- if (rx_bytes && tx_bytes) {
1530
- result = calcNetworkSpeed(ifaceName, parseInt(rx_bytes), parseInt(tx_bytes), operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
1531
- }
1532
- resolve(result);
1533
- });
1534
- });
1535
- }
1536
- } else {
1537
- result.rx_bytes = _network[ifaceSanitized].rx_bytes;
1538
- result.tx_bytes = _network[ifaceSanitized].tx_bytes;
1539
- result.rx_sec = _network[ifaceSanitized].rx_sec;
1540
- result.tx_sec = _network[ifaceSanitized].tx_sec;
1541
- result.ms = _network[ifaceSanitized].last_ms;
1542
- result.operstate = _network[ifaceSanitized].operstate;
1543
- resolve(result);
1544
- }
1545
- });
1546
- });
1547
- }
1548
-
1549
- exports.networkStats = networkStats;
1550
-
1551
- // --------------------------
1552
- // NET - connections (sockets)
1553
-
1554
- function getProcessName(processes, pid) {
1555
- let cmd = '';
1556
- processes.forEach((line) => {
1557
- const parts = line.split(' ');
1558
- const id = parseInt(parts[0], 10) || -1;
1559
- if (id === pid) {
1560
- parts.shift();
1561
- cmd = parts.join(' ').split(':')[0];
1562
- }
1563
- });
1564
- cmd = cmd.split(' -')[0];
1565
- cmd = cmd.split(' /')[0];
1566
- return cmd;
1567
- // const cmdParts = cmd.split('/');
1568
- // return cmdParts[cmdParts.length - 1];
1569
- }
1570
-
1571
- function networkConnections(callback) {
1572
- return new Promise((resolve) => {
1573
- process.nextTick(() => {
1574
- const result = [];
1575
- if (_linux || _freebsd || _openbsd || _netbsd) {
1576
- let cmd =
1577
- 'export LC_ALL=C; netstat -tunap | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"; unset LC_ALL';
1578
- if (_freebsd || _openbsd || _netbsd) {
1579
- cmd =
1580
- 'export LC_ALL=C; netstat -na | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"; unset LC_ALL';
1581
- }
1582
- exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
1583
- let lines = stdout.toString().split('\n');
1584
- if (!error && (lines.length > 1 || lines[0] !== '')) {
1585
- lines.forEach((line) => {
1586
- line = line.replace(/ +/g, ' ').split(' ');
1587
- if (line.length >= 7) {
1588
- let localip = line[3];
1589
- let localport = '';
1590
- const localaddress = line[3].split(':');
1591
- if (localaddress.length > 1) {
1592
- localport = localaddress[localaddress.length - 1];
1593
- localaddress.pop();
1594
- localip = localaddress.join(':');
1595
- }
1596
- let peerip = line[4];
1597
- let peerport = '';
1598
- const peeraddress = line[4].split(':');
1599
- if (peeraddress.length > 1) {
1600
- peerport = peeraddress[peeraddress.length - 1];
1601
- peeraddress.pop();
1602
- peerip = peeraddress.join(':');
1603
- }
1604
- const connstate = line[5];
1605
- const proc = line[6].split('/');
1606
-
1607
- if (connstate) {
1608
- result.push({
1609
- protocol: line[0],
1610
- localAddress: localip,
1611
- localPort: localport,
1612
- peerAddress: peerip,
1613
- peerPort: peerport,
1614
- state: connstate,
1615
- pid: proc[0] && proc[0] !== '-' ? parseInt(proc[0], 10) : null,
1616
- process: proc[1] ? proc[1].split(' ')[0].split(':')[0] : ''
1617
- });
1618
- }
1619
- }
1620
- });
1621
- if (callback) {
1622
- callback(result);
1623
- }
1624
- resolve(result);
1625
- } else {
1626
- cmd = 'ss -tunap | grep "ESTAB\\|SYN-SENT\\|SYN-RECV\\|FIN-WAIT1\\|FIN-WAIT2\\|TIME-WAIT\\|CLOSE\\|CLOSE-WAIT\\|LAST-ACK\\|LISTEN\\|CLOSING"';
1627
- exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
1628
- if (!error) {
1629
- const lines = stdout.toString().split('\n');
1630
- lines.forEach((line) => {
1631
- line = line.replace(/ +/g, ' ').split(' ');
1632
- if (line.length >= 6) {
1633
- let localip = line[4];
1634
- let localport = '';
1635
- const localaddress = line[4].split(':');
1636
- if (localaddress.length > 1) {
1637
- localport = localaddress[localaddress.length - 1];
1638
- localaddress.pop();
1639
- localip = localaddress.join(':');
1640
- }
1641
- let peerip = line[5];
1642
- let peerport = '';
1643
- const peeraddress = line[5].split(':');
1644
- if (peeraddress.length > 1) {
1645
- peerport = peeraddress[peeraddress.length - 1];
1646
- peeraddress.pop();
1647
- peerip = peeraddress.join(':');
1648
- }
1649
- let connstate = line[1];
1650
- if (connstate === 'ESTAB') {
1651
- connstate = 'ESTABLISHED';
1652
- }
1653
- if (connstate === 'TIME-WAIT') {
1654
- connstate = 'TIME_WAIT';
1655
- }
1656
- let pid = null;
1657
- let process = '';
1658
- if (line.length >= 7 && line[6].indexOf('users:') > -1) {
1659
- const proc = line[6].replace('users:(("', '').replace(/"/g, '').replace('pid=', '').split(',');
1660
- if (proc.length > 2) {
1661
- process = proc[0];
1662
- const pidValue = parseInt(proc[1], 10);
1663
- if (pidValue > 0) {
1664
- pid = pidValue;
1665
- }
1666
- }
1667
- }
1668
- if (connstate) {
1669
- result.push({
1670
- protocol: line[0],
1671
- localAddress: localip,
1672
- localPort: localport,
1673
- peerAddress: peerip,
1674
- peerPort: peerport,
1675
- state: connstate,
1676
- pid,
1677
- process
1678
- });
1679
- }
1680
- }
1681
- });
1682
- }
1683
- if (callback) {
1684
- callback(result);
1685
- }
1686
- resolve(result);
1687
- });
1688
- }
1689
- });
1690
- }
1691
- if (_darwin) {
1692
- const cmd = 'netstat -natvln | head -n2; netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6"';
1693
- const states = 'ESTABLISHED|SYN_SENT|SYN_RECV|FIN_WAIT1|FIN_WAIT_1|FIN_WAIT2|FIN_WAIT_2|TIME_WAIT|CLOSE|CLOSE_WAIT|LAST_ACK|LISTEN|CLOSING|UNKNOWN'.split('|');
1694
- exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
1695
- if (!error) {
1696
- exec('ps -axo pid,command', { maxBuffer: 1024 * 102400 }, (err2, stdout2) => {
1697
- let processes = stdout2.toString().split('\n');
1698
- processes = processes.map((line) => {
1699
- return line.trim().replace(/ +/g, ' ');
1700
- });
1701
- const lines = stdout.toString().split('\n');
1702
- lines.shift();
1703
- let pidPos = 8;
1704
- if (lines.length > 1 && lines[0].indexOf('pid') > 0) {
1705
- const header = (lines.shift() || '')
1706
- .replace(/ Address/g, '_Address')
1707
- .replace(/process:/g, '')
1708
- .replace(/ +/g, ' ')
1709
- .split(' ');
1710
- pidPos = header.indexOf('pid');
1711
- }
1712
- lines.forEach((line) => {
1713
- line = line.replace(/ +/g, ' ').split(' ');
1714
- if (line.length >= 8) {
1715
- let localip = line[3];
1716
- let localport = '';
1717
- const localaddress = line[3].split('.');
1718
- if (localaddress.length > 1) {
1719
- localport = localaddress[localaddress.length - 1];
1720
- localaddress.pop();
1721
- localip = localaddress.join('.');
1722
- }
1723
- let peerip = line[4];
1724
- let peerport = '';
1725
- const peeraddress = line[4].split('.');
1726
- if (peeraddress.length > 1) {
1727
- peerport = peeraddress[peeraddress.length - 1];
1728
- peeraddress.pop();
1729
- peerip = peeraddress.join('.');
1730
- }
1731
- const hasState = states.indexOf(line[5]) >= 0;
1732
- const connstate = hasState ? line[5] : 'UNKNOWN';
1733
- let pidField = '';
1734
- if (line[line.length - 9] && line[line.length - 9].indexOf(':') >= 0) {
1735
- pidField = line[line.length - 9].split(':')[1];
1736
- } else {
1737
- pidField = line[pidPos + (hasState ? 0 : -1)] || '';
1738
-
1739
- if (pidField.indexOf(':') >= 0) {
1740
- pidField = pidField.split(':')[1];
1741
- }
1742
- }
1743
- const pid = parseInt(pidField, 10);
1744
- if (connstate) {
1745
- result.push({
1746
- protocol: line[0],
1747
- localAddress: localip,
1748
- localPort: localport,
1749
- peerAddress: peerip,
1750
- peerPort: peerport,
1751
- state: connstate,
1752
- pid: pid,
1753
- process: getProcessName(processes, pid)
1754
- });
1755
- }
1756
- }
1757
- });
1758
- if (callback) {
1759
- callback(result);
1760
- }
1761
- resolve(result);
1762
- });
1763
- } else {
1764
- if (callback) {
1765
- callback(result);
1766
- }
1767
- resolve(result);
1768
- }
1769
- });
1770
- }
1771
- if (_windows) {
1772
- let cmd = 'netstat -nao';
1773
- try {
1774
- exec(cmd, util.execOptsWin, (error, stdout) => {
1775
- if (!error) {
1776
- let lines = stdout.toString().split('\r\n');
1777
-
1778
- lines.forEach((line) => {
1779
- line = line.trim().replace(/ +/g, ' ').split(' ');
1780
- if (line.length >= 4) {
1781
- let localip = line[1];
1782
- let localport = '';
1783
- const localaddress = line[1].split(':');
1784
- if (localaddress.length > 1) {
1785
- localport = localaddress[localaddress.length - 1];
1786
- localaddress.pop();
1787
- localip = localaddress.join(':');
1788
- }
1789
- localip = localip.replace(/\[/g, '').replace(/\]/g, '');
1790
- let peerip = line[2];
1791
- let peerport = '';
1792
- const peeraddress = line[2].split(':');
1793
- if (peeraddress.length > 1) {
1794
- peerport = peeraddress[peeraddress.length - 1];
1795
- peeraddress.pop();
1796
- peerip = peeraddress.join(':');
1797
- }
1798
- peerip = peerip.replace(/\[/g, '').replace(/\]/g, '');
1799
- const pid = util.toInt(line[4]);
1800
- let connstate = line[3];
1801
- if (connstate === 'HERGESTELLT') {
1802
- connstate = 'ESTABLISHED';
1803
- }
1804
- if (connstate.startsWith('ABH')) {
1805
- connstate = 'LISTEN';
1806
- }
1807
- if (connstate === 'SCHLIESSEN_WARTEN') {
1808
- connstate = 'CLOSE_WAIT';
1809
- }
1810
- if (connstate === 'WARTEND') {
1811
- connstate = 'TIME_WAIT';
1812
- }
1813
- if (connstate === 'SYN_GESENDET') {
1814
- connstate = 'SYN_SENT';
1815
- }
1816
-
1817
- if (connstate === 'LISTENING') {
1818
- connstate = 'LISTEN';
1819
- }
1820
- if (connstate === 'SYN_RECEIVED') {
1821
- connstate = 'SYN_RECV';
1822
- }
1823
- if (connstate === 'FIN_WAIT_1') {
1824
- connstate = 'FIN_WAIT1';
1825
- }
1826
- if (connstate === 'FIN_WAIT_2') {
1827
- connstate = 'FIN_WAIT2';
1828
- }
1829
- if (line[0].toLowerCase() !== 'udp' && connstate) {
1830
- result.push({
1831
- protocol: line[0].toLowerCase(),
1832
- localAddress: localip,
1833
- localPort: localport,
1834
- peerAddress: peerip,
1835
- peerPort: peerport,
1836
- state: connstate,
1837
- pid,
1838
- process: ''
1839
- });
1840
- } else if (line[0].toLowerCase() === 'udp') {
1841
- result.push({
1842
- protocol: line[0].toLowerCase(),
1843
- localAddress: localip,
1844
- localPort: localport,
1845
- peerAddress: peerip,
1846
- peerPort: peerport,
1847
- state: '',
1848
- pid: parseInt(line[3], 10),
1849
- process: ''
1850
- });
1851
- }
1852
- }
1853
- });
1854
- if (callback) {
1855
- callback(result);
1856
- }
1857
- resolve(result);
1858
- } else {
1859
- if (callback) {
1860
- callback(result);
1861
- }
1862
- resolve(result);
1863
- }
1864
- });
1865
- } catch {
1866
- if (callback) {
1867
- callback(result);
1868
- }
1869
- resolve(result);
1870
- }
1871
- }
1872
- });
1873
- });
1874
- }
1875
-
1876
- exports.networkConnections = networkConnections;
1877
-
1878
- function networkGatewayDefault(callback) {
1879
- return new Promise((resolve) => {
1880
- process.nextTick(() => {
1881
- let result = '';
1882
- if (_linux || _freebsd || _openbsd || _netbsd) {
1883
- const cmd = 'ip route get 1';
1884
- try {
1885
- exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
1886
- if (!error) {
1887
- let lines = stdout.toString().split('\n');
1888
- const line = lines && lines[0] ? lines[0] : '';
1889
- let parts = line.split(' via ');
1890
- if (parts && parts[1]) {
1891
- parts = parts[1].split(' ');
1892
- result = parts[0];
1893
- }
1894
- if (callback) {
1895
- callback(result);
1896
- }
1897
- resolve(result);
1898
- } else {
1899
- if (callback) {
1900
- callback(result);
1901
- }
1902
- resolve(result);
1903
- }
1904
- });
1905
- } catch {
1906
- if (callback) {
1907
- callback(result);
1908
- }
1909
- resolve(result);
1910
- }
1911
- }
1912
- if (_darwin) {
1913
- let cmd = 'route -n get default';
1914
- try {
1915
- exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
1916
- if (!error) {
1917
- const lines = stdout
1918
- .toString()
1919
- .split('\n')
1920
- .map((line) => line.trim());
1921
- result = util.getValue(lines, 'gateway');
1922
- }
1923
- if (!result) {
1924
- cmd = "netstat -rn | awk '/default/ {print $2}'";
1925
- exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
1926
- const lines = stdout
1927
- .toString()
1928
- .split('\n')
1929
- .map((line) => line.trim());
1930
- result = lines.find((line) =>
1931
- /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(line)
1932
- );
1933
- if (callback) {
1934
- callback(result);
1935
- }
1936
- resolve(result);
1937
- });
1938
- } else {
1939
- if (callback) {
1940
- callback(result);
1941
- }
1942
- resolve(result);
1943
- }
1944
- });
1945
- } catch {
1946
- if (callback) {
1947
- callback(result);
1948
- }
1949
- resolve(result);
1950
- }
1951
- }
1952
- if (_windows) {
1953
- try {
1954
- exec('netstat -r', util.execOptsWin, (error, stdout) => {
1955
- const lines = stdout.toString().split(os.EOL);
1956
- lines.forEach((line) => {
1957
- line = line.replace(/\s+/g, ' ').trim();
1958
- if (line.indexOf('0.0.0.0 0.0.0.0') > -1 && !/[a-zA-Z]/.test(line)) {
1959
- const parts = line.split(' ');
1960
- if (parts.length >= 5 && parts[parts.length - 3].indexOf('.') > -1) {
1961
- result = parts[parts.length - 3];
1962
- }
1963
- }
1964
- });
1965
- if (!result) {
1966
- util.powerShell("Get-CimInstance -ClassName Win32_IP4RouteTable | Where-Object { $_.Destination -eq '0.0.0.0' -and $_.Mask -eq '0.0.0.0' }").then((data) => {
1967
- let lines = data.toString().split('\r\n');
1968
- if (lines.length > 1 && !result) {
1969
- result = util.getValue(lines, 'NextHop');
1970
- if (callback) {
1971
- callback(result);
1972
- }
1973
- resolve(result);
1974
- // } else {
1975
- // exec('ipconfig', util.execOptsWin, function (error, stdout) {
1976
- // let lines = stdout.toString().split('\r\n');
1977
- // lines.forEach(function (line) {
1978
- // line = line.trim().replace(/\. /g, '');
1979
- // line = line.trim().replace(/ +/g, '');
1980
- // const parts = line.split(':');
1981
- // if ((parts[0].toLowerCase().startsWith('standardgate') || parts[0].toLowerCase().indexOf('gateway') > -1 || parts[0].toLowerCase().indexOf('enlace') > -1) && parts[1]) {
1982
- // result = parts[1];
1983
- // }
1984
- // });
1985
- // if (callback) { callback(result); }
1986
- // resolve(result);
1987
- // });
1988
- }
1989
- });
1990
- } else {
1991
- if (callback) {
1992
- callback(result);
1993
- }
1994
- resolve(result);
1995
- }
1996
- });
1997
- } catch {
1998
- if (callback) {
1999
- callback(result);
2000
- }
2001
- resolve(result);
2002
- }
2003
- }
2004
- });
2005
- });
2006
- }
2007
-
2008
- exports.networkGatewayDefault = networkGatewayDefault;