Class: NetUtils
Defined in: service-core/src/NetUtils.ts:12
Provides common utilities and functions for working with networking related problems.
Constructors
Constructor
new NetUtils():
NetUtils
Returns
NetUtils
Methods
getIPAddress()
staticgetIPAddress(urlOrRequest,trustedProxies?):string|undefined
Defined in: service-core/src/NetUtils.ts:57
Extracts the IP address from a given url or HTTP request.
When trustedProxies is provided, forwarding headers (X-Forwarded-For, etc.) are
only trusted when the direct connection's remoteAddress is in that list. Without a
trusted-proxy list the headers are ignored and the socket address is returned directly,
preventing clients from spoofing their IP in audit logs.
Parameters
urlOrRequest
string | HttpRequest
The url or HTTP request to extract the IP from.
trustedProxies?
string[]
Optional list of proxy IP addresses whose forwarding headers should be trusted.
Returns
string | undefined
A string containing the IP address if found, otherwise undefined.
lookupIPAddress()
staticlookupIPAddress(url,family?):Promise<string|undefined>
Defined in: service-core/src/NetUtils.ts:20
Performs DNS lookup of the IP address from a given url.
Parameters
url
string
The url to lookup the IP from.
family?
number = 4
ip family used for dns lookup
Returns
Promise<string | undefined>
A string containing the IP address if found, otherwise undefined.