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

23
LINES

< > BotCompany Repo | #1028654 // IP-to-country standalone demo

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (2141L/14K).

!7

set flag LeanMode.

static File dbFile() {
  ret assertFileExists(new File("IP2LOCATION-LITE-DB1.CSV"));
}

p {
  if (empty(args))
    ret with print("Please supply an IP number as the argument to get the country name.");
    
  S ip = args[0];
  long ipNum = ipToInt(ip);
  
  S line = pairB(binarySearchForLineInTextFile(dbFile(), s -> {
    LS l = tok_splitAtComma_unquote(s);
    long a = parseLongOpt(first(l)), b = parseLongOpt(second(l));
    ret ipNum > b ? 1 : ipNum < a ? -1 : 0;
  }));
  
  print(or2(get(tok_splitAtComma_unquote(line), 2), "unknown"));
}

Author comment

Began life as a copy of #1028338

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028654
Snippet name: IP-to-country standalone demo
Eternal ID of this version: #1028654/11
Text MD5: 3ff4c7f28b998b2559eef327d8ed52f6
Transpilation MD5: 7243ff817e5320fe02cda6e76b6731c7
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-02 11:47:01
Source code size: 592 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 135 / 525
Version history: 10 change(s)
Referenced in: [show references]