In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "using ip-attribution.dat files to achieve IP attribution query". In daily operation, I believe many people have doubts about using ip-attribution.dat files to achieve IP attribution query. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "using ip-attribution.dat files to achieve IP attribution query". Next, please follow the editor to study!
Use ip-attribution.dat file to implement IP attribution query. Download address
Download the extraction code of the network disk: 2chr
Package com.sky.common.utils;import cn.hutool.core.io.resource.ClassPathResource;import org.apache.commons.lang3.StringUtils;import java.io.*;import java.net.Inet4Address;import java.net.InetAddress;import java.net.UnknownHostException;import java.nio.ByteBuffer;import java.nio.ByteOrder;import java.util.Arrays;import java.util.HashMap;import java.util.Map / * ip Home Resolution * * @ author Moses wsj1198878990@126.com * @ since 1.0.0 2019-10-22 * / public final class IPDataHandler {private static DataInputStream inputStream = null; private static long fileLength =-1; private static int dataLength =-1; private static Map cacheMap = null; private static byte [] allData = null; static {/ / File file = new File (IP_DATA_PATH) Try {/ / put the file under src/main/resources File file = new ClassPathResource ("ip-attribution.dat") .getFile (); inputStream = new DataInputStream (new FileInputStream (file)); fileLength = file.length (); cacheMap = new HashMap () If (fileLength > Integer.MAX_VALUE) {throw new Exception ("the filelength over 2GB");} dataLength = (int) fileLength; allData = new byte [dataLength]; inputStream.read (allData, 0, dataLength); dataLength = (int) getbytesTolong (allData, 0,4, ByteOrder.BIG_ENDIAN) } catch (FileNotFoundException e) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace ();} catch (Exception e) {e.printStackTrace () }} private static long getbytesTolong (byte [] bytes, int offerSet, int size, ByteOrder byteOrder) {if ((offerSet + size) > bytes.length | | size 255) {return "illegal ip";} if (cacheMap.containsKey (ip)) {return cacheMap.get (ip);} long numIp = 1 Try {numIp = ip2long (address);} catch (UnknownHostException E1) {e1.printStackTrace ();} int tempOffSet = ipHeadValue * 4 + 4; long start = getbytesTolong (allData, tempOffSet, 4, ByteOrder.LITTLE_ENDIAN); int max_len = dataLength-1028; long resultOffSet = 0; int resultSize = 0 For (start = start * 8 + 1024; start
< max_len; start += 8) { if (getbytesTolong(allData, (int) start + 4, 4, ByteOrder.BIG_ENDIAN) >= numIp) {resultOffSet = getIntByBytes (allData, (int) (start + 4 + 4)); resultSize = (char) allData [(int) start + 7 + 4]; break;}} if (resultOffSet
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.