.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); } }
收到好多消息,让我聊一下阿里云国际版本,作为一个阿里云死忠粉,之前用的服务器都是阿里云国内版的VPS主机,对于现在火热的阿里云国际版,这段时间了解了下,觉得还是有很多部分可以聊的,毕竟,实名制的服务器规则导致国际版无需实名这一特点被无限放大。以前也写过几篇综合性的阿里云国际版vps的分析,其中有一点得到很多人的认同,那句是阿里云不管国内版还是国际版的IO读写速度实在不敢恭维,相对意义上的,如果在这...
GigsGigsCloud新上了洛杉矶机房国际版线路VPS,基于KVM架构,采用SSD硬盘,年付最低26美元起。这是一家成立于2015年的马来西亚主机商,提供VPS主机和独立服务器租用,数据中心包括美国洛杉矶、中国香港、新加坡、马来西亚和日本等。商家VPS主机基于KVM架构,所选均为国内直连或者优化线路,比如洛杉矶机房有CN2 GIA、AS9929或者高防线路等。下面列出这款年付VPS主机配置信息...
SugarHosts 糖果主机商也算是比较老牌的主机商,从2009年开始推出虚拟主机以来,目前当然还是以虚拟主机为主,也有新增云服务器和独立服务器。早年很多网友也比较争议他们家是不是国人商家,其实这些不是特别重要,我们很多国人商家或者国外商家主要还是看重的是品质和服务。一晃十二年过去,有看到SugarHosts糖果主机商12周年的促销活动。如果我们有需要香港、美国、德国虚拟主机的可以选择,他们家的...