note 46807 deleted from function.gethostbyaddr by sean

From: Date: Sun, 24 Oct 2004 17:01:17 +0000
Subject: note 46807 deleted from function.gethostbyaddr by sean
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79041@lists.php.net to get a copy of this message
Note Submitter: vgr at europeanexperts dot org ---- For all who want the country out of the IP@ All the solutions below won't help a lot in that case. The most of the IP@ I see coming to my server resolve to non-country TLDs (.net, .org, .com and such). Moreover, I performed time measurements for the various solutions presented below : - direct nslookup via a system call( exec() ) - GetHostByAddr() call - my own & old-styled clumsy solution I used so far (I am searching for a faster alternative) and I found out that (I must state now that I'm on a Win2K Apache) the most reliable solution is my old one, and that it is also - surprisingly enough - the fastest method in most cases. Examples : 1) for 80.65.230.177 my solution provides 'FR-NERIM-20010515 : PROVIDER (FR)' (and thus country='FR') in 515.09213 milliseconds system call to nslookup FAILS in 377.67196 milliseconds GetHostByAddr() FAILS in 4508.01492 milliseconds 2) for 82.65.118.217 my solution provides 'FR-PROXAD-ADSL : Proxad / Free SAS : Dynamic pool (IP/ADSL FT) : NCC#2003105812 (FR)' (country is obvious) in 1030.53808 milliseconds system call to nslookup FAILS in 520.73598 milliseconds GetHostByAddr() provides 'lns-p19-18-82-65-118-217.adsl.proxad.net' in 5.23996 milliseconds : that's FAST, but the country is yet unknown (NET isn't a country) 3) for 213.37.180.126 my solution provides 'MADRITEL : PROVIDER : Madritel (ES)' in 659.18517 milliseconds with country='ES' system call to nslookup FAILS in 438.81083 milliseconds GetHostByAddr() provides '126.red-213-37-180.user.auna.net' in 184.0589 milliseconds : same remarks as above 4) for 212.100.173.102 my solution provides 'EASYNET-BE-ADSL : Easynet Belgium (BE)' in 856.97699 milliseconds with country='BE' system call to nslookup FAILS in 425.40908 milliseconds GetHostByAddr() provides '212-100-173-102.adsl.easynet.be' in 114.74204 milliseconds with country='BE' So my conclusion is : - do not ever try to exec(nslookup) - at least on zindoze - because it will mostly fail with a loooong time consumed - try the fast GetHostByAddr() in case it gives you a country (and not .com, .net, .org or other non-countries TLDs) - then as a last resort use my old-styled solution (based on HTTP whois calls and nslookup in last resort) This is not the fastest method (depends whether you're lucky GetHostByAddr() returns you a country or not) but it's the most reliable. Moreover, it seems that GetHostByAddr() is maintaining some kind of cache for the results ! (some come out in 0.4 ms ) Hope this helps some people around. You can find my test script at http://www.fecj.org/extra/getCountryByIP_fast_demo.php.txt VGR ----------------------- www.europeanexperts.org ---- Reason: useless note

« previous php.notes (#79041) next »