• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Inet6Address类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中java.net.Inet6Address的典型用法代码示例。如果您正苦于以下问题:Scala Inet6Address类的具体用法?Scala Inet6Address怎么用?Scala Inet6Address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Inet6Address类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Subnet

//设置package包名称以及导入依赖的类
package com.github.shadowsocks.acl

import java.net.{Inet4Address, Inet6Address, InetAddress}

import com.github.shadowsocks.utils.Utils


@throws[IllegalArgumentException]
class Subnet(val address: InetAddress, val prefixSize: Int) extends Comparable[Subnet] {
  if (prefixSize < 0) throw new IllegalArgumentException
  address match {
    case _: Inet4Address => if (prefixSize > 32) throw new IllegalArgumentException
    case _: Inet6Address => if (prefixSize > 128) throw new IllegalArgumentException
  }

  override def toString: String = if (address match {
    case _: Inet4Address => prefixSize == 32
    case _: Inet6Address => prefixSize == 128
  }) address.getHostAddress else address.getHostAddress + '/' + prefixSize

  override def compareTo(that: Subnet): Int = {
    val addrThis = address.getAddress
    val addrThat = that.address.getAddress
    var result = addrThis lengthCompare addrThat.length // IPv4 address goes first
    if (result != 0) return result
    for ((x, y) <- addrThis zip addrThat) {
      result = (x & 0xFF) compare (y & 0xFF)  // undo sign extension of signed byte
      if (result != 0) return result
    }
    prefixSize compare that.prefixSize
  }
}

object Subnet {
  @throws[IllegalArgumentException]
  def fromString(value: String): Subnet = {
    val parts = value.split("/")
    if (!Utils.isNumeric(parts(0))) throw new IllegalArgumentException()
    val addr = InetAddress.getByName(parts(0))
    parts.length match {
      case 1 => new Subnet(addr, addr match {
        case _: Inet4Address => 32
        case _: Inet6Address => 128
      })
      case 2 => new Subnet(addr, parts(1).toInt)
      case _ => throw new IllegalArgumentException()
    }
  }
} 
开发者ID:rallets-network,项目名称:rallets-android,代码行数:50,代码来源:Subnet.scala


示例2: GeoIp

//设置package包名称以及导入依赖的类
package com.bwsw.sj.examples.sflow.module.process.udf

import java.net.{Inet4Address, Inet6Address, InetAddress}

import com.bwsw.sj.common.DAL.repository.ConnectionRepository
import com.bwsw.sj.common.utils.ConfigSettingsUtils
import com.maxmind.geoip.LookupService
import org.slf4j.LoggerFactory

object GeoIp {
  private val logger = LoggerFactory.getLogger(this.getClass)

  private val fileStorage = ConnectionRepository.getFileStorage

  private lazy val ipv4AsNumLookup = getAsLookupServiceIpv4
  private lazy val ipv6AsNumLookup = getAsLookupServiceIpv6

  def resolveAs(ip: String): Int = {
    try {
      InetAddress.getByName(ip) match {
        case _: Inet4Address =>
          if (ipv4AsNumLookup.getID(ip) != 0) ipv4AsNumLookup.getOrg(ip).split(" ")(0).substring(2).toInt else 0
        case _: Inet6Address =>
          if (ipv6AsNumLookup.getID(ip) != 0) ipv6AsNumLookup.getOrgV6(ip).split(" ")(0).substring(2).toInt else 0
      }
    } catch {
      case _: java.net.UnknownHostException =>
        throw new Exception( s"""resolveAs error: "$ip" isn't correct ip address""")
      case _: com.maxmind.geoip.InvalidDatabaseException =>
        logger.error( s"""resolveAs error: "$ip" com.maxmind.geoip.InvalidDatabaseException""")
        0
    }
  }

  private def getAsLookupServiceIpv4 = {
    val geoIpFileName = ConfigSettingsUtils.getGeoIpAsNumFileName()

    createLookupService(geoIpFileName)
  }

  private def getAsLookupServiceIpv6 = {
    val geoIpFileName = ConfigSettingsUtils.getGeoIpAsNumv6FileName()

    createLookupService(geoIpFileName)
  }
  
  private def createLookupService(filename: String) = {
    val databaseFile = fileStorage.get(filename, filename)

    new LookupService(databaseFile)
  }
} 
开发者ID:bwsw,项目名称:sj-platform,代码行数:53,代码来源:GeoIp.scala


示例3: net

//设置package包名称以及导入依赖的类
package refined.guava.net

import java.net.{Inet4Address, Inet6Address}

import com.google.common.net.{InetAddresses, InternetDomainName, MediaType}
import eu.timepit.refined.api.Validate
import refined.guava.net.net.{DNS, IP, IPv4, IPv6, Media}

object net extends NetValidate {
  case class IP()
  case class IPv4()
  case class IPv6()
  case class DNS()
  case class Media()
}

private[net] trait NetValidate {
  implicit def ipValidate: Validate.Plain[String, IP] =
    Validate.fromPartial(InetAddresses.forString, "IP Address", IP())

  implicit def ipv4Validate: Validate.Plain[String, IPv4] =
    Validate.fromPredicate(
      str => InetAddresses.forString(str).isInstanceOf[Inet4Address],
      str => s"$str is not an IPv4 Address",
      IPv4())

  implicit def ipv6Validate: Validate.Plain[String, IPv6] =
    Validate.fromPredicate(
      str => InetAddresses.forString(str).isInstanceOf[Inet6Address],
      str => s"$str is not an IPv6 Address",
      IPv6())


  implicit def dnsValidate: Validate.Plain[String, DNS] =
    Validate.fromPartial(InternetDomainName.from, "DNS name", DNS())

  implicit def mediaValidate: Validate.Plain[String, Media] =
    Validate.fromPartial(MediaType.parse, "MediaType", Media())

} 
开发者ID:derekmorr,项目名称:refined-guava,代码行数:41,代码来源:net.scala


示例4: Pinger

//设置package包名称以及导入依赖的类
package net.woaf.jono.phonehome

import java.net.{ Inet6Address, InetAddress }
import scala.sys.process._ // scalastyle:ignore

class Pinger(addr: InetAddress, interface: String) extends HostStatusChecker {

  private val isWindows = System.getProperty("os.name").toLowerCase().contains("win")

  private val isv6 = addr match {
    case a: Inet6Address => true
    case _ => false
  }

  override def isHostAlive: Boolean =
    (
      if (isWindows) {
        Seq("ping", "-w", "1000", "-n", "1", addr.getHostAddress)
      } else if (isv6) {
        Seq("ping6", if (!interface.isEmpty) s"-I$interface" else "", "-W", "1", "-n", "-c", "1", addr.getHostAddress)
      } else {
        Seq("ping", "-W", "1", "-n", "-c", "1", addr.getHostAddress)
      }
    ) ! ProcessLogger(
        line => {},
        line => {}
      ) == 0
} 
开发者ID:JonathanO,项目名称:phonehome,代码行数:29,代码来源:Pinger.scala



注:本文中的java.net.Inet6Address类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala SourceMapper类代码示例发布时间:2022-05-23
下一篇:
Scala Supervision类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap