Create a public or private ip
772781
def create(gandi, datacenter, bandwidth, ip_version, vlan, ip, attach,
           background):
    
    if ip_version != 4 and vlan:
        gandi.echo('You must have an --ip-version to 4 when having a vlan.')
        return

    if ip and not vlan:
        gandi.echo('You must have a --vlan when giving an --ip.')
        return

    vm_ = gandi.iaas.info(attach) if attach else None

    if datacenter and vm_:
        dc_id = gandi.datacenter.usable_id(datacenter)
        if dc_id != vm_['datacenter_id']:
            gandi.echo('The datacenter you provided does not match the '
                       'datacenter of the vm you want to attach to.')
            return

    if not datacenter:
        datacenter = vm_['datacenter_id'] if vm_ else 'LU'

    try:
        gandi.datacenter.is_opened(datacenter, 'iaas')
    except DatacenterLimited as exc:
        gandi.echo('/!\ Datacenter %s will be closed on %s, '
                   'please consider using another datacenter.' %
                   (datacenter, exc.date))

    return gandi.ip.create(ip_version, datacenter, bandwidth, attach,
                           vlan, ip, background)
846242
def create_ip_arp_request(srchw, srcip, targetip):
    '''
    
    '''
    ether = Ethernet()
    ether.src = srchw
    ether.dst = SpecialEthAddr.ETHER_BROADCAST.value
    ether.ethertype = EtherType.ARP
    arp = Arp()
    arp.operation = ArpOperation.Request
    arp.senderhwaddr = srchw
    arp.senderprotoaddr = srcip
    arp.targethwaddr = SpecialEthAddr.ETHER_BROADCAST.value
    arp.targetprotoaddr = targetip
    return ether + arp
404881
function ip(conf) {
    var MSG="非法ip";
    if (typeof conf !== 'object') {
        if (typeof conf === 'string') {
            conf = {whiteList: [conf]};
        } else {
            conf = {
            };
        }
    }
    if (Array.isArray(conf)) {
        conf = {whiteList: conf};
    }
    return function* (next) {
        var _this=this;
        var _ip = typeof conf.proxy === 'function' ? conf.proxy.call(_this, _this) : this.ip;
        var pass = false;
        if (conf.whiteList && Array.isArray(conf.whiteList)) {
            pass = conf.whiteList.some(function (item) {
                return RegExp(item).test(_ip);
            });
        }
        if (conf.blackList && Array.isArray(conf.blackList)) {
            pass = !conf.blackList.some(function (item) {
                return RegExp(item).test(_ip);
            });
        }
        if (pass) {
            console.log((new Date).toUTCString() + ' ' + _ip + ' -> ok');
            yield next;
        } else {
            console.log((new Date).toUTCString() + ' ' + _ip + ' -> no');
            _this.status=403;
            _this.body=conf.msg||MSG;
        }
    }
}
993131
private function setIp()
    {
        if (class_exists($Ip = 'Josantonius\Ip\Ip')) {
            $ip = $Ip::get();
            $this->setOption('IP', ($ip) ? $ip : 'unknown');
        }
    }
996011
def create_ip_arp_reply(srchw, dsthw, srcip, targetip):
    '''
    
    '''
    pkt = create_ip_arp_request(srchw, srcip, targetip)
    pkt[0].dst = dsthw
    pkt[1].operation = ArpOperation.Reply
    pkt[1].targethwaddr = dsthw
    return pkt
412078
function createServer (options, callback) {
  typeforce({
    keeper: 'Object',
    port: 'Number',
    readonly: '?Boolean'
  }, options)

  var keeper = options.keeper
  var port = options.port
  var app = express()
  if (options.readonly) {
    app.set('readonly', true)
  }

  // var mapping

  app.set('keeper', keeper)
  app.use(function (req, res, next) {
    var requestDomain = domain.create()
    requestDomain.add(req)
    requestDomain.add(res)
    requestDomain.on('error', function (err) {
      debug('Uncaught error, processing in domain error handler: ' + err.message)
      errorHandler(err, req, res)
    })

    res.on('close', requestDomain.dispose.bind(requestDomain))
    requestDomain.run(next)
  })

  app.use(function (req, res, next) {
    if (req.hostname !== 'localhost' && req.hostname !== '127.0.0.1') {
      throw utils.httpError(400, 'Only local requests permitted')
    }

    next()
  })

  /**
   * Routes
   */
  router(app)

  /**
   * Error Handling
   */
  app.use(errorHandler)

  // client.externalIp(function(err, ip) {
  //   console.log('External ip', ip)
  //   keeper.externalIp(ip)
  // })

  // var ttl = 144000

  process.on('exit', cleanup)
  process.on('SIGINT', cleanup)
  process.on('SIGTERM', cleanup)
  process.on('uncaughtException', function (err) {
    console.log('Uncaught exception, caught in process catch-all: ' + err.message)
    console.log(err.stack)
  })

  // if (require.main === global.module) {
  // run directly, not as sub-app

  // var mappingIntervalId = setInterval(createPortMapping, ttl)
  // var pubPort = port
  var privPort = port
  var serverIsUp
  // var portPromise = createPortMapping()
  // portPromise.done(checkReady)

  var server = app.listen(privPort, function () {
    serverIsUp = true
    checkReady()
  })

  function checkReady () {
    if (serverIsUp
      // && portPromise.inspect().state === 'fulfilled'
      && callback) {
      callback(null, server)
    }
  }

  function errorHandler (err, req, res, next) {
    if (res.finished) return

    var code = err.code || 500
    var msg = 'code' in err ? err.message : 'There was an error with your request. Please contact support@tradle.io'

    // log('Error:' + err.message)
    res.status(code).json({
      code: code,
      message: msg
    }, null, 2)
  }

  // function createPortMapping () {
  //   return ports.mapPort({
  //       public: pubPort,
  //       private: privPort,
  //       hijack: true
  //     })
  //     .then(function () {
  //       mapping = {
  //         public: pubPort,
  //         private: privPort
  //       }
  //     })
  //     .catch(function (err) {
  //       console.error('Failed to create port mapping, but continuing', err)
  //       clearInterval(mappingIntervalId)
  //     // process.exit()
  //     })
  // }

  function cleanup () {
    if (!server) return

    debug('CLEANUP')
    if (server) {
      try {
        server.close()
      } catch (err) {}
      server = null
    }

    // if (mapping) {
    //   clearInterval(mappingIntervalId)
    //   ports.unmapPort(mapping['public'])
    //   mapping = null
    // }

    setTimeout(process.exit.bind(process), 1000)
  }

  return server
}
1043454
def get_public_ip_address(ip_address)
      params = {
          'command' => 'listPublicIpAddresses',
          'ipaddress' => ip_address
      }
      json = send_request(params)
      return nil unless json['publicipaddress']
      json['publicipaddress'].first
    end
312604
def floating_ip_create(kwargs, call=None):
    '''
    
    '''
    if call != 'function':
        raise SaltCloudSystemExit(
            'The floating_ip_create action must be called with -f or --function'
        )

    if 'pool' not in kwargs:
        log.error('pool is required')
        return False

    conn = get_conn()
    return conn.floating_ip_create(kwargs['pool'])
1052494
def ip():
    """"""
    ok, err = _hack_ip()
    if not ok:
        click.secho(click.style(err, fg='red'))
        sys.exit(1)
    click.secho(click.style(err, fg='green'))
533948
def create(gandi, resource, flags, algorithm, public_key):
    """"""

    result = gandi.dnssec.create(resource, flags, algorithm, public_key)

    return result
731201
def create_ip_cert_links(ssl_dir, custom_hostname_link=None):
    
    hostname = get_hostname(unit_get('private-address'))
    hostname_cert = os.path.join(
        ssl_dir,
        'cert_{}'.format(hostname))
    hostname_key = os.path.join(
        ssl_dir,
        'key_{}'.format(hostname))
    # Add links to hostname cert, used if os-hostname vars not set
    for net_type in [INTERNAL, ADMIN, PUBLIC]:
        try:
            addr = resolve_address(endpoint_type=net_type)
            cert = os.path.join(ssl_dir, 'cert_{}'.format(addr))
            key = os.path.join(ssl_dir, 'key_{}'.format(addr))
            if os.path.isfile(hostname_cert) and not os.path.isfile(cert):
                os.symlink(hostname_cert, cert)
                os.symlink(hostname_key, key)
        except NoNetworkBinding:
            log("Skipping creating cert symlink for ip in {} space, no "
                "local address found".format(net_type), WARNING)
    if custom_hostname_link:
        custom_cert = os.path.join(
            ssl_dir,
            'cert_{}'.format(custom_hostname_link))
        custom_key = os.path.join(
            ssl_dir,
            'key_{}'.format(custom_hostname_link))
        if os.path.isfile(hostname_cert) and not os.path.isfile(custom_cert):
            os.symlink(hostname_cert, custom_cert)
            os.symlink(hostname_key, custom_key)
237191
def ipv4_public(self, network=False, address_class=None):
        
        # compute public networks
        public_networks = [_IPv4Constants._network_classes[
            address_class or self.ipv4_network_class()
        ]]

        # exclude private and excluded special networks
        public_networks = self._exclude_ipv4_networks(
            public_networks,
            _IPv4Constants._private_networks +
            _IPv4Constants._excluded_networks,
        )

        # choose random public network from the list
        public_network = self.generator.random.choice(public_networks)

        return self._random_ipv4_address_from_subnet(public_network, network)
127761
def is_private(self):
        
        private_10 = IPv4Network(u'10.0.0.0/8')
        private_172 = IPv4Network(u'172.16.0.0/12')
        private_192 = IPv4Network(u'192.168.0.0/16')
        return (self in private_10 or
                self in private_172 or
                self in private_192)
1122126
def _waitForIP(cls, instance):
        
        logger.debug('Waiting for ip...')
        while True:
            time.sleep(a_short_time)
            instance.update()
            if instance.ip_address or instance.public_dns_name or instance.private_ip_address:
                logger.debug('...got ip')
                break
1208240
def get_instance_private_ip_from_route(instance, route):
    
    ipaddr = None
    for eni in instance.interfaces:
        if eni.id == route.interface_id:
            ipaddr = eni.private_ip_address
            break
    return ipaddr, eni if ipaddr else None
670798
static function sp($ip = null) {return dfcf(function($ip = null) {return new self([
		self::$P__IP => $ip ?: df_visitor_ip()
	]);}, [$ip]);}
972971
def _get_ip_public(self, queue_target, url, json=False, key=None):
        """"""
        try:
            response = urlopen(url, timeout=self.timeout).read().decode('utf-8')
        except Exception as e:
            logger.debug("IP plugin - Cannot open URL {} ({})".format(url, e))
            queue_target.put(None)
        else:
            # Request depend on service
            try:
                if not json:
                    queue_target.put(response)
                else:
                    queue_target.put(loads(response)[key])
            except ValueError:
                queue_target.put(None)