MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / getIPAddress

Function getIPAddress

javascript/selenium-webdriver/net/index.js:38–57  ·  view source on GitHub ↗

* Queries the system network interfaces for an IP address. * @param {boolean} loopback Whether to find a loopback address. * @param {string} family The IP family (IPv4 or IPv6). Defaults to IPv4. * @return {(string|undefined)} The located IP address or undefined.

(loopback, family)

Source from the content-addressed store, hash-verified

36 * @return {(string|undefined)} The located IP address or undefined.
37 */
38function getIPAddress(loopback, family) {
39 let interfaces
40 if (loopback) {
41 const lo = getLoInterface()
42 interfaces = lo ? [lo] : null
43 }
44 interfaces = interfaces || os.networkInterfaces()
45 for (let key in interfaces) {
46 if (!Object.prototype.hasOwnProperty.call(interfaces, key)) {
47 continue
48 }
49
50 for (let ipAddress of interfaces[key]) {
51 if ((ipAddress.family === family || `IPv${ipAddress.family}` === family) && ipAddress.internal === loopback) {
52 return ipAddress.address
53 }
54 }
55 }
56 return undefined
57}
58
59// PUBLIC API
60

Callers 2

getAddressFunction · 0.85
getLoopbackAddressFunction · 0.85

Calls 2

getLoInterfaceFunction · 0.85
callMethod · 0.65

Tested by

no test coverage detected