{"id":19387666,"url":"https://github.com/haraka/haraka-net-utils","last_synced_at":"2025-04-23T23:31:20.966Z","repository":{"id":11636800,"uuid":"70195561","full_name":"haraka/haraka-net-utils","owner":"haraka","description":"haraka network utilities","archived":false,"fork":false,"pushed_at":"2025-01-31T20:32:40.000Z","size":145,"stargazers_count":2,"open_issues_count":0,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-14T14:48:55.918Z","etag":null,"topics":["haraka","network","smtp","utilities"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/haraka-net-utils","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haraka.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-06T21:42:46.000Z","updated_at":"2025-01-31T20:32:26.000Z","dependencies_parsed_at":"2024-05-02T22:57:43.708Z","dependency_job_id":null,"html_url":"https://github.com/haraka/haraka-net-utils","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haraka%2Fharaka-net-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haraka%2Fharaka-net-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haraka%2Fharaka-net-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haraka%2Fharaka-net-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haraka","download_url":"https://codeload.github.com/haraka/haraka-net-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250531973,"owners_count":21446094,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haraka","network","smtp","utilities"],"created_at":"2024-11-10T10:10:06.710Z","updated_at":"2025-04-23T23:31:20.943Z","avatar_url":"https://github.com/haraka.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI][ci-img]][ci-url]\n[![Code Coverage][cov-img]][cov-url]\n[![Code Climate][clim-img]][clim-url]\n\n# haraka-net-utils\n\nThis module provides network utility functions.\n\n## Usage\n\n```js\nconst net_utils = require('haraka-net-utils')`\n```\n\n### ip_to_long\n\n```js\n// Convert IPv4 to long\nconst long = net_utils.ip_to_long('11.22.33.44') // 185999660\n```\n\n### long_to_ip\n\n```js\n// Convert long to IPv4\nconst ip = net_utils.long_to_ip(185999660) // 11.22.33.44\n```\n\n### dec_to_hex\n\n```js\n// Convert decimal to hex\nconst hex = net_utils.dec_to_hex(20111104) // 132df00\n```\n\n### hex_to_dec\n\n```js\n// Convert hex to decimal\nconst dec = net_utils.hex_to_dec('132df00') // 20111104\n```\n\n### is_local_ipv4\n\n```js\n// Is IPv4 address on a local network?\nnet_utils.is_local_ipv4('127.0.0.200') // true (localhost)\nnet_utils.is_local_ipv4('169.254.0.0') // true (link local)\nnet_utils.is_local_ipv4('226.0.0.1') // false\n```\n\n### is_private_ipv4\n\n```js\n// Is IPv4 address in RFC 1918 reserved private address space?\nnet_utils.is_private_ipv4('10.0.0.0') // true\nnet_utils.is_private_ipv4('192.168.0.0') // true\nnet_utils.is_private_ipv4('172.16.0.0') // true\n```\n\n### is_local_ipv6\n\n```js\n// Is IPv6 addr on local network?\nnet_utils.is_local_ipv6('::1') // true (localhost)\nnet_utils.is_local_ipv6('fe80::') // true (link local)\nnet_utils.is_local_ipv6('fc00::') // true (unique local)\nnet_utils.is_local_ipv6('fd00::') // true (unique local)\n```\n\n### is_private_ip\n\nDetermines if an IPv4 or IPv6 address is on a \"private\" network.\nFor IPv4, returns true if is_private_ipv4 or is_local_ipv4 are true\nFor IPv6, returns true if is_local_ipv6 is true\n\n### is_local_host\n\nChecks to see if a host name matches our server hostname or resolves to any local ip. Local IPs include those bound to a local network interface and public IPs discovered with STUN.\n\n### is_local_ip\n\nChecks to see if an IP is bound locally or an IPv4 or IPv6 localhost address.\n\n### ip_in_list\n\n```js\n// searches for 'ip' as a hash key in the list object or array\n// ip can be a host, an IP, or an IPv4 or IPv6 range\nnet_utils.ip_in_list(object, ip)\nnet_utils.ip_in_list(array, ip)\nnet_utils.ip_in_list(tls.no_tls_hosts, '127.0.0.5')\n```\n\n### get_ips_by_host\n\nReturns an array of all the IPv4 and IPv6 addresses of the provided hostname.\n\n```js\ntry {\n  const ips = await net_utils.get_ips_by_host(domain)\n  for (const ip of ips) {\n    // do something with the IPs\n  }\n} catch (err) {\n  // handle any errors\n}\n```\n\n### get_mx\n\n```js\ntry {\n  const mxList = await net_utils.get_mx(domain)\n  for (const mx of mxList) {\n    // do something with each mx\n  }\n} catch (err) {\n  // handle any errors\n}\n```\n\n### HarakaMx\n\nAn object class representing a MX. HarakaMx objects may contain the following properties:\n\n```js\n{\n  exchange: '', // required: a FQDN or IP address\n  path: '', // the file path to a socket\n  priority: 0, // integer, a MX priority.\n  port: 25, // integer: an alternate port\n  bind: '', // an outbound IP address to bind to\n  bind_helo: '', // an outbound helo hostname\n  using_lmtp: false, // boolean, specify LMTP delivery\n  auth_user: '', // an AUTH username (required if AUTH is desired)\n  auth_pass: '', // an AUTH password (required if AUTH is desired)\n  auth_type: '', // an AUTH type that should be used with the MX.\n  from_dns: '', // the DNS name from which the MX was queried\n}\n```\n\nCreate a HarakaMx object in The Usual Way:\n\n```js\nconst nu = require('haraka-net-utils')\nconst myMx = new nu.HarakaMx(parameter)\n```\n\nThe parameter can be one of:\n\n- A string in any of the following formats:\n  - hostname\n  - hostname:port\n  - IPv4\n  - IPv4:port\n  - [IPv6]\n  - [IPv6]: port\n- A [URL](https://nodejs.org/docs/latest-v20.x/api/url.html) string\n  - smtp://mail.example.com:25\n  - lmtp://int-mail.example.com:24\n  - smtp://user:pass@host.example.com:587\n- An object, containing at least an exchange, and any of the other properties listed at the top of this section.\n\nAn optional second parameter is an alias for from_dns.\n\n[ci-img]: https://github.com/haraka/haraka-net-utils/actions/workflows/ci.yml/badge.svg\n[ci-url]: https://github.com/haraka/haraka-net-utils/actions/workflows/ci.yml\n[cov-img]: https://codecov.io/github/haraka/haraka-net-utils/coverage.svg\n[cov-url]: https://codecov.io/github/haraka/haraka-net-utils\n[clim-img]: https://codeclimate.com/github/haraka/haraka-net-utils/badges/gpa.svg\n[clim-url]: https://codeclimate.com/github/haraka/haraka-net-utils\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharaka%2Fharaka-net-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharaka%2Fharaka-net-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharaka%2Fharaka-net-utils/lists"}