How to use the isV4Format function from ip

Find comprehensive JavaScript ip.isV4Format code examples handpicked from public code repositorys.

149
150
151
152
153
154
155
156
157
158
} else {
  let cidrParts = val.split("/", 2);
  if (cidrParts.length == 2) {
    let addr = cidrParts[0];
    let mask = cidrParts[1];
    if (ip.isV4Format(addr) && RegExp("^\\d+$").test(mask) && ip.isV4Format(val2)) {
      // try matching cidr subnet iff value in alarm is an ipv4 address and value in exception is a cidr notation
      if (!ip.cidrSubnet(val).contains(val2)) {
        return false;
      }
fork icon117
star icon467
watch icon48

2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
  if (rule) {
    matchedRules.push(rule);
  }
} else if (['block_ip_set', 'sec_block_ip_set'].includes(ipsetName) && iptool.isV4Format(currentTxt)) {
  matchedRules = rules.filter(rule => rule.type == "ip" && rule.target === currentTxt);
} else if (['block_net_set', 'sec_block_net_set'].includes(ipsetName) && iptool.isV4Format(currentTxt)) {
  matchedRules = rules.filter(rule => rule.type == "net" && iptool.cidrSubnet(rule.target).contains(currentTxt));
} else if (['block_domain_set', 'sec_block_domain_set'].includes(ipsetName) && iptool.isV4Format(currentTxt)) {
  const filterRules = rules.filter(rule => ["dns", "domain"].includes(rule.type));
  if (isDomain) {
fork icon117
star icon463
watch icon0

+ 17 other calls in file

171
172
173
174
175
176
177
178
179
180
let entry = this.activeMac[mac];
let host = {
  mac: mac,
  from: "macHeartbeat"
};
if (entry.ipv4Addr && iptool.isV4Format(entry.ipv4Addr)) {
  host.ipv4 = entry.ipv4Addr;
  host.ipv4Addr = entry.ipv4Addr;
}
if (entry.ipv6Addr && Array.isArray(entry.ipv6Addr) && entry.ipv6Addr.length > 0) {
fork icon117
star icon463
watch icon0

116
117
118
119
120
121
122
123
124
125
        dbg.log0_throttled('failed to ipify', err);
    }
}

function is_ip(address) {
    return ip_module.isV4Format(address) || ip_module.isV6Format(address);
}

function find_ifc_containing_address(address) {
    const family =
fork icon70
star icon229
watch icon17

371
372
373
374
375
376
377
378
379
380
381
382


/**
 * Check if a hostname should be proxied or not
 */
function should_proxy(hostname) {
    const isIp = ip.isV4Format(hostname) || ip.isV6Format(hostname);


    for (const { kind, addr } of no_proxy_list) {
        if (isIp) {
            if (kind === 'IP' && ip.isEqual(addr, hostname)) {
fork icon68
star icon227
watch icon0

+ 2 other calls in file

93
94
95
96
97
98
99
100
101
102
 * @param {boolean} loopback - Allows contacts that are localhost
 * @returns {boolean}
 */
module.exports.isValidContact = function(contact, loopback) {
  const [, info] = contact;
  const isValidAddr = ip.isV4Format(info.hostname) ||
                      ip.isV6Format(info.hostname) ||
                      ip.isPublic(info.hostname);
  const isValidPort = info.port > 0;
  const isAllowedAddr = ip.isLoopback(info.hostname) ? !!loopback : true;
fork icon20
star icon1
watch icon0

+ 2 other calls in file

887
888
889
890
891
892
893
894
895
// these are removed from the hostname in url.parse(),
// so we have the pure IPv6-address in hostname.
// always allow localhost host, for convenience (hostname === 'localhost')
// allow hostname of listening address  (hostname === this.hostname)
const isValidHostname =
  ip.isV4Format(hostname) ||
  ip.isV6Format(hostname) ||
  hostname === 'localhost' ||
  hostname === this.hostname;
fork icon0
star icon0
watch icon1

+ 3 other calls in file

186
187
188
189
190
191
192
193
194
195
196
module.exports.isValidContact = function(contact, loopback) {
  if (!contact) {
    return false;
  }


  var isValidAddr = ip.isV4Format(contact.address) ||
                    ip.isV6Format(contact.address) ||
                    ip.isPublic(contact.address);
  var isValidPort = contact.port > 0;
  var isAllowedAddr = ip.isLoopback(contact.address) ? !!loopback : true;
fork icon0
star icon0
watch icon0

1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
let dnsResult = null;

if (result && result.stdout && result.stdout.trim().length !== 0)  {
  let lines = result.stdout.trim().split("\n");
  lines = lines.filter((l) => {
    return ip.isV4Format(l) || ip.isV6Format(l);
  });
  if (lines.length !== 0) {
    dnsResult = lines[0];
  }
fork icon0
star icon0
watch icon0

12
13
14
15
16
17
18
19
20
21
 * @see RVN-4024
 * @param {String} value - строка с именем домена
 * @returns {String}
 */
function getDomainName(value) {
  if (!value || ipUtils.isV4Format(value) || ipUtils.isV6Format(value)) {
    return null;
  }

  const domain = String(value).split('.');
fork icon0
star icon0
watch icon23

+ 3 other calls in file