.ip;
import java.io.ByteArrayOutputStream; import java.io.IOException; import essFile;
public class QQWry { private String DbPath = "D:\QQWry2.Dat"; private String Country, LocalStr; private long IPN; private int RecordCount, CountryFlag; private long RangE, RangB, OffSet, StartIP, EndIP, FirstStartIP, LastStartIP, EndIPOff; private essFile fis; private byte[] buff;
public String getLocal() { return this.LocalStr; }
public String getCountry() { return this.Country; }
public void setPath(String path) { this.DbPath = path; } private long B2L(byte[] b) { long ret = 0; for (int i = 0; i < b.length; i++) { long t = 1L; for (int j = 0; j < i; j++) t = t * 256L; ret += ((b[i] < 0) ? 256 + b[i] : b[i]) * t; } return ret; }
private long ipToInt(String ip) { String[] arr = ip.split("\."); long ret = 0; for (int i = 0; i < arr.length; i++) { long l = 1; for (int j = 0; j < i; j++) l *= 256; try { ret += Long.parseLong(arr[arr.length - i - 1]) * l; } catch (Exception e) { ret += 0; } } return ret; }
public void seek(String ip) throws Exception { this.IPN = ipToInt(ip); fis = new essFile(this.DbPath, "r"); buff = new byte[4]; fis.seek(0); fis.read(buff); FirstStartIP = this.B2L(buff); fis.read(buff); LastStartIP = this.B2L(buff); RecordCount = (int) ((LastStartIP - FirstStartIP) / 7); if (RecordCount <= 1) { LocalStr = Country = "δ?"; throw new Exception(); }
RangB = 0; RangE = RecordCount; long RecNo;
do { RecNo = (RangB + RangE) / 2; getStartIP(RecNo); if (IPN == StartIP) { RangB = RecNo; break; } if (IPN > StartIP) RangB = RecNo; else RangE = RecNo; } while (RangB < RangE - 1);
getStartIP(RangB); getEndIP(); getCountry(IPN);
fis.close(); }
private String getFlagStr(long OffSet) throws IOException { int flag = 0; do { fis.seek(OffSet); buff = new byte[1]; fis.read(buff); flag = (buff[0] < 0) ? 256 + buff[0] : buff[0]; if (flag == 1 || flag == 2) { buff = new byte[3]; fis.read(buff); if (flag == 2) { CountryFlag = 2; EndIPOff = OffSet - 4; } OffSet = this.B2L(buff); } else break; } while (true);
if (OffSet < 12) { return ""; } else { fis.seek(OffSet); return getStr(); } }
private String getStr() throws IOException { long l = fis.length(); ByteArrayOutputStream byteout = new ByteArrayOutputStream(); byte c = fis.readByte(); do { byteout.write(c); c = fis.readByte(); } while (c != 0 && fis.getFilePointer() < l); return byteout.toString(); }
private void getCountry(long ip) throws IOException { if (CountryFlag == 1 || CountryFlag == 2) { Country = getFlagStr(EndIPOff + 4); if (CountryFlag == 1) { LocalStr = getFlagStr(fis.getFilePointer()); if (IPN >= ipToInt("255.255.255.0") && IPN <= ipToInt("255.255.255.255")) { LocalStr = getFlagStr(EndIPOff + 21); Country = getFlagStr(EndIPOff + 12); } } else { LocalStr = getFlagStr(EndIPOff + 8); } } else { Country = getFlagStr(EndIPOff + 4); LocalStr = getFlagStr(fis.getFilePointer()); } }
private long getEndIP() throws IOException { fis.seek(EndIPOff); buff = new byte[4]; fis.read(buff); EndIP = this.B2L(buff); buff = new byte[1]; fis.read(buff); CountryFlag = (buff[0] < 0) ? 256 + buff[0] : buff[0]; return EndIP; }
private long getStartIP(long RecNo) throws IOException { OffSet = FirstStartIP + RecNo * 7; fis.seek(OffSet); buff = new byte[4]; fis.read(buff); StartIP = this.B2L(buff); buff = new byte[3]; fis.read(buff); EndIPOff = this.B2L(buff); return StartIP; }
public String getIpAddr(String ip) throws Exception{ seek(ip); String ctron = new String(getCountry().getBytes(), "GBK"); String area = new String(getLocal().getBytes(), "GBk"); return ctron + area; }
public static void main(String[] args) throws Exception { QQWry w = new QQWry(); // w.setPath(new File("QQWry2.Dat").getAbsolutePath()); w.seek("202.120.40.1"); String ctron = new String(w.getCountry().getBytes(), "GBK"); String area = new String(w.getLocal().getBytes(), "GBk"); System.out.println(ctron + area); } }
BuyVM 商家算是有一些年头,从早年提供低价便宜VPS主机深受广大网友抢购且也遭到吐槽的是因为审核账户太过于严格。毕竟我们国内的个人注册账户喜欢账户资料乱写,毕竟我们看英文信息有些还是比较难以识别的,于是就注册信息的时候随便打一些字符,这些是不能通过的。前几天,我们可以看到BUYVM商家有新增加迈阿密机房,而且商家有提供大硬盘且不限制流量的VPS主机,深受有一些网友的喜欢。目前,BUYVM商家有...
racknerd怎么样?racknerd美国便宜vps又开启促销模式了,机房优秀,有洛杉矶DC-02、纽约、芝加哥机房可选,最低配置4TB月流量套餐16.55美元/年,此外商家之前推出的最便宜的9.49美元/年套餐也补货上架,同时RackNerd美国AMD VPS套餐最低才14.18美元/年,是全网最便宜的AMD VPS套餐!RackNerd主要经营美国圣何塞、洛杉矶、达拉斯、芝加哥、亚特兰大、新...
iON Cloud怎么样?iON Cloud是Krypt旗下的云服务器品牌,成立于2019年,是美国老牌机房(1998~)krypt旗下的VPS云服务器品牌,主打国外VPS云服务器业务,均采用KVM架构,整体性能配置较高,云服务器产品质量靠谱,在线率高,国内直连线路,适合建站等用途,支付宝、微信付款购买。支持Windows server 2012、2016、2019中英文版本以及主流Linux发行...