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包下載地址:
漳浦網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)2013年至今到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
https://www.mvnjar.com/com.github.seancfoley/ipaddress/5.0.2/detail.html