Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #1008728 // Test IP to country [old database]

JavaX source code [tags: archive use-pretranspiled] - run with: x30.jar

Uses 51K of libraries. Click here for Pure Java version (3971L/27K/87K).

!7

sclass Item {
  long end;
  S country;
}

static new TreeMap<Long, Item> data;

p {
  for (S s : lines(readerToString(utf8bufferedReader(lzmaInputStream(#1004343))))) {
    L<S> l = tok_splitAtComma_unquote(s);
    if (l(l) < 3) continue;
    long start = parseLong(first(l));
    long end = parseLong(second(l));
    S country = intern(l.get(4));
    data.put(start, nuWithValues(Item, +end, +country));
  }
  print(l(data) + " " + first(keys(data)));
  botSleep();
}

answer {
  long ip = ipToInt(trim(s));
  print("s=" + s + ", ip=" + ip);
  Long key = data.floorKey(ip);
  if (key != null) {
    Item i = data.get(key);
    if (i != null) ret i.country;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): cfunsshuasjs, mqqgnosmbjvj, nbgitpuheiab, tvejysmllsmz

No comments. add comment

Snippet ID: #1008728
Snippet name: Test IP to country [old database]
Eternal ID of this version: #1008728/14
Text MD5: c2274bdf7da1194ed8469bb86176ab0e
Transpilation MD5: b69a00e738276245bfaf787b714a16df
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): Yes
Created/modified: 2017-05-31 17:32:08
Source code size: 697 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 437 / 550
Version history: 13 change(s)
Referenced in: [show references]