package?test; import?java.io.ByteArrayOutputStream; import?java.io.DataOutputStream; import?java.io.IOException; import?java.util.ArrayList; import?java.util.Iterator; import?java.util.List; import?inet.ipaddr.IPAddress; import?inet.ipaddr.IPAddressString; import?inet.ipaddr.ipv4.IPv4Address; public?class?TestIpAddr?{ public?static?void?main(String[]?args)?{ //ip轉(zhuǎn)bigint IPAddress?address?=?new?IPAddressString("192.168.1.1").getAddress()?; System.out.println(?address.getValue()??); //?bigint轉(zhuǎn)ip System.out.println(String.join(".",new?IPv4Address(toByteArray(3232235777L)).getSegmentStrings())); //獲取子網(wǎng) List?subnetList?=?getSubnetList("192.168.1.1/255.255.252.0"); for(int?i=0;i ?getSubnetList?(String?ipAddr){ ????????IPAddress?address?=?new?IPAddressString(ipAddr).getAddress(); ????????int?prefixLength=address.toAddressString().getNetworkPrefixLength(); ????????List ?subnetList?=?new?ArrayList (); ????????IPAddress?subnet?=?address.applyPrefixLength(prefixLength).toPrefixBlock(); ????????Iterator?extends?IPAddress>?iterator?=?subnet.iterator(); ???????? ????????while?(iterator.hasNext())?{ ????????????subnetList.add(iterator.next().toCanonicalWildcardString()); ????????} ????????subnetList.remove(0); ????????subnetList.remove(subnetList.size()-1); ????????return??subnetList; ????} ???? }
jar包下載地址:
為平原等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及平原網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為做網(wǎng)站、成都網(wǎng)站設(shè)計、平原網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!https://www.mvnjar.com/com.github.seancfoley/ipaddress/5.0.2/detail.html
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統(tǒng)配攻擊溯源,準確進行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。