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).

1  
!7
2  
3  
set flag LeanMode.
4  
5  
static File dbFile() {
6  
  ret assertFileExists(new File("IP2LOCATION-LITE-DB1.CSV"));
7  
}
8  
9  
p {
10  
  if (empty(args))
11  
    ret with print("Please supply an IP number as the argument to get the country name.");
12  
    
13  
  S ip = args[0];
14  
  long ipNum = ipToInt(ip);
15  
  
16  
  S line = pairB(binarySearchForLineInTextFile(dbFile(), s -> {
17  
    LS l = tok_splitAtComma_unquote(s);
18  
    long a = parseLongOpt(first(l)), b = parseLongOpt(second(l));
19  
    ret ipNum > b ? 1 : ipNum < a ? -1 : 0;
20  
  }));
21  
  
22  
  print(or2(get(tok_splitAtComma_unquote(line), 2), "unknown"));
23  
}

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: 245 / 768
Version history: 10 change(s)
Referenced in: [show references]