473,466 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using string functions

i am using $ip= $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
the client for example if the value returned from $ip is
50.160.190.150

i would like to find out which country the request has come from. i
believe by using the third set of numbers (in this case=190) from an
ip address we can find out the country name. i can declare a variable
with a list of country names and the range of values, what i need help
is to extract the 3rd set of numbers from $ip.

as ip address keep changing the 3rd set of numbers can be single,
double or 3 digit number how can we extract the number that is stored
in $ip after the second dot and before the third dot

please advice.

thanks.
Jul 14 '08 #1
10 2009

"Sudhakar" <su***********@gmail.comwrote in message
news:f1**********************************@d77g2000 hsb.googlegroups.com...
>i am using $ip= $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
the client for example if the value returned from $ip is
50.160.190.150

i would like to find out which country the request has come from. i
believe by using the third set of numbers (in this case=190) from an
ip address we can find out the country name. i can declare a variable
with a list of country names and the range of values, what i need help
is to extract the 3rd set of numbers from $ip.

as ip address keep changing the 3rd set of numbers can be single,
double or 3 digit number how can we extract the number that is stored
in $ip after the second dot and before the third dot

please advice.

thanks.
have a look at this..

http://www.phpclasses.org/browse/package/1477.html

I see explode used to extract the "."

Hope this helps..
Jul 14 '08 #2
have a look at this..
>
http://www.phpclasses.org/browse/package/1477.html

I see explode used to extract the "."

Hope this helps..
yes, i agree with sathyashrayan, explode is what you need

$ip = $_SERVER['REMOTE_ADDR'];
$array_ip = explode('.',$ip);
$third_octet = $ip[2]; //remember, array = zero based
Claudio
Jul 14 '08 #3
On Jul 14, 1:33 pm, Sudhakar <sudhakarar...@gmail.comwrote:
i am using $ip= $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
the client for example if the value returned from $ip is
50.160.190.150
To get the 3rd Octet, you may {explode} the string as the previous
posters have said...

But if you have to get the Country Information, you'll have to get if
from a database.. Entire DBs like IP2Location etc. can be purchased..
(commecial, very accurate results)

Also, Try HostIP to get country informtion. They have a good API..
[FREE]
First, get the IP using $ip= $_SERVER['REMOTE_ADDR'];
Get the country and city name with
http://api.hostip.info/get_html.php?ip=$_SERVER['REMOTE_ADDR']
Try an example http://api.hostip.info/get_html.php?ip=222.88.238.16 -
This will show and example of the output format. Get the text contents
using $data = @file_get_contents($_GET['url']); or something and
extract the info from there//

Try that .. Hope it helps...

Cheers !
Dj

>
i would like to find out which country the request has come from. i
believe by using the third set of numbers (in this case=190) from an
ip address we can find out the country name. i can declare a variable
with a list of country names and the range of values, what i need help
is to extract the 3rd set of numbers from $ip.

as ip address keep changing the 3rd set of numbers can be single,
double or 3 digit number how can we extract the number that is stored
in $ip after the second dot and before the third dot

please advice.

thanks.


On Jul 14, 1:33*pm, Sudhakar <sudhakarar...@gmail.comwrote:
i am using $ip= $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
the client for example if the value returned from $ip is
50.160.190.150

i would like to find out which country the request has come from. i
believe by using the third set of numbers (in this case=190) from an
ip address we can find out the country name. i can declare a variable
with a list of country names and the range of values, what i need help
is to extract the 3rd set of numbers from $ip.

as ip address keep changing the 3rd set of numbers can be single,
double or 3 digit number how can we extract the number that is stored
in $ip after the second dot and before the third dot

please advice.

thanks.
Jul 14 '08 #4
On 14 jul, 11:50, thinkdj <think...@gmail.comwrote:
First, get the IP using $ip= $_SERVER['REMOTE_ADDR'];
Get the country and city name withhttp://api.hostip.info/get_html.php?ip=$_SERVER['REMOTE_ADDR']
Try an examplehttp://api.hostip.info/get_html.php?ip=222.88.238.16-
This will show and example of the output format. Get the text contents
using $data = @file_get_contents($_GET['url']); or something and
extract the info from there//
what a nice tip! thanks for that!
Jul 14 '08 #5
..oO(Sudhakar)
>i am using $ip= $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
the client for example if the value returned from $ip is
50.160.190.150

i would like to find out which country the request has come from.
This can't be done reliably, not even with GeoIP databases. An IP is not
bound to any particular country nor does it say anything about where the
user is actually. All you can get are informations about the company the
IP belongs to.
>i
believe by using the third set of numbers (in this case=190) from an
ip address we can find out the country name.
Where did you get that from? It's totally wrong. There's absolutely no
country information contained in an IP address, it's just an unsigned
32bit number (in case of IPv4).

Micha
Jul 14 '08 #6
On 14 jul, 17:21, Michael Fesser <neti...@gmx.dewrote:
.oO(Sudhakar)
i am using $ip= $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
the client for example if the value returned from $ip is
50.160.190.150
i would like to find out which country the request has come from.

This can't be done reliably, not even with GeoIP databases. An IP is not
bound to any particular country nor does it say anything about where the
user is actually. All you can get are informations about the company the
IP belongs to.
i
believe by using the third set of numbers (in this case=190) from an
ip address we can find out the country name.

Where did you get that from? It's totally wrong. There's absolutely no
country information contained in an IP address, it's just an unsigned
32bit number (in case of IPv4).

Micha
well, maybe you can't obtain one hundred percent reliable data about
the country, not even when you ask to the user, but with the ip you
can at least try to guess, better than nothing don't you think?
Jul 15 '08 #7
..oO(Claudio Corlatti)
>well, maybe you can't obtain one hundred percent reliable data about
the country, not even when you ask to the user, but with the ip you
can at least try to guess, better than nothing don't you think?
Sure, it's a guess. Not more. Question is still for what the OP wants to
use it.

Micha
Jul 15 '08 #8
Claudio Corlatti wrote:
On 14 jul, 17:21, Michael Fesser <neti...@gmx.dewrote:
>.oO(Sudhakar)
>>i am using $ip= $_SERVER['REMOTE_ADDR'] to retrieve the ip address of
the client for example if the value returned from $ip is
50.160.190.150
i would like to find out which country the request has come from.
This can't be done reliably, not even with GeoIP databases. An IP is not
bound to any particular country nor does it say anything about where the
user is actually. All you can get are informations about the company the
IP belongs to.
>>i
believe by using the third set of numbers (in this case=190) from an
ip address we can find out the country name.
Where did you get that from? It's totally wrong. There's absolutely no
country information contained in an IP address, it's just an unsigned
32bit number (in case of IPv4).

Micha

well, maybe you can't obtain one hundred percent reliable data about
the country, not even when you ask to the user, but with the ip you
can at least try to guess, better than nothing don't you think?
Actually its probably a lot better than a guess, since you normally
apply to the organisation in the country in which you are operating, for
an IP address range.

e.g.

#whois 86.30.134.0

OrgName: RIPE Network Coordination Centre
OrgID: RIPE
Address: P.O. Box 10096
City: Amsterdam
StateProv:
PostalCode: 1001EB
Country: NL

ReferralServer: whois://whois.ripe.net:43

NetRange: 86.0.0.0 - 86.255.255.255
CIDR: 86.0.0.0/8
NetName: 86-RIPE
NetHandle: NET-86-0-0-0-1
Parent:
NetType: Allocated to RIPE NCC
NameServer: NS-PRI.RIPE.NET
NameServer: NS3.NIC.FR
NameServer: SEC1.APNIC.NET
NameServer: SEC3.APNIC.NET
NameServer: SUNIC.SUNET.SE
NameServer: TINNIE.ARIN.NET
NameServer: NS.LACNIC.NET
Comment: These addresses have been further assigned to users in
Comment: the RIPE NCC region. Contact information can be found in
Comment: the RIPE database at http://www.ripe.net/whois
RegDate: 2004-04-01
Updated: 2004-04-06

# ARIN WHOIS database, last updated 2008-07-14 19:10
# Enter ? for additional hints on searching ARIN's WHOIS database.
% This is the RIPE Whois query server #3.
% The objects are in RPSL format.
%
% Rights restricted by copyright.
% See http://www.ripe.net/db/copyright.html

% Note: This output has been filtered.
% To receive output for a database update, use the "-B" flag.

% Information related to '86.30.0.0 - 86.30.255.255'

inetnum: 86.30.0.0 - 86.30.255.255
netname: NTL
descr: NTL Infrastructure - NTL Freedom
country: GB
admin-c: NNMC1-RIPE
tech-c: NNMC1-RIPE
status: ASSIGNED PA
mnt-by: AS5089-MNT
source: RIPE # Filtered

role: NTLI Network Management Centre
address: NTL Internet
address: Crawley Court
address: Winchester
address: Hampshire
address: SO21 2QA
phone: +44 1633710142
admin-c: MH22007-RIPE
admin-c: NR731-RIPE
admin-c: CW1083-RIPE
tech-c: MH22007-RIPE
tech-c: CW1083-RIPE
nic-hdl: NNMC1-RIPE
mnt-by: AS5089-MNT
e-mail: pi*@virginmedia.co.uk
source: RIPE # Filtered

% Information related to '86.0.0.0/11AS5089'

route: 86.0.0.0/11
descr: NTL-UK-IP-BLOCK
origin: AS5089
mnt-by: AS5089-MNT
remarks: report abuse to www.virginmedia.com/netreport +44
(0)1633 710142
source: RIPE # Filtered
Jul 15 '08 #9
..oO(The Natural Philosopher)
>Actually its probably a lot better than a guess, since you normally
apply to the organisation in the country in which you are operating, for
an IP address range.
Ever heard of proxy servers and international ISPs like AOL?
It might be a good guess, but it's still just a guess.

Micha
Jul 15 '08 #10
Michael Fesser wrote:
.oO(The Natural Philosopher)
>Actually its probably a lot better than a guess, since you normally
apply to the organisation in the country in which you are operating, for
an IP address range.

Ever heard of proxy servers and international ISPs like AOL?
been involved with them for years. Intenational ISPs generally STILL use
netblocks registered in the country they are currently operating in, (it
makes for economical routing if nothing else) and whilst its possible to
use proxy server in china to access the USA from Europe, it generally is
a bit of a waste of time unles you are deliberately trying to hide your
tracks.

It might be a good guess, but it's still just a guess.
Apart from the proxy issue its more than a good guess. You can
generally ID the ISP's physical point of presence given the IP address
of the source ..

If you trace mine..think its in the headers..it will tell you probably
somewhere in North London or Essex. Only 60 miles away from me.
Micha
Jul 15 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Russ | last post by:
I'm trying to use InteropServices in a web service, by following the examples and info in the article "Consuming Unmanaged DLL Functions" in the .NET Framework Developer's Guide. I am able to...
1
by: Junior | last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could not be found (are you missing a using directive or an assembly reference?)" message in two particular lines, and I've...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
7
by: techno | last post by:
Dear all, Our bitmap has some x00 values ( '\0' ) and i am storing it in char* array. the problem is that the '\0' is treated as eos character in c and it is truncating it so the characters...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
8
by: FS Liu | last post by:
Hi, I am writing ATL Service application (XML Web service) in VS.NET C++. Are there any sample programs that accept XML as input and XML as output in the web service? Thank you very much.
14
by: B Williams | last post by:
I am stuck on an assignment that uses classes and functions. I am receiving numerous errors when I try to run a test program to see if I wrote it correctly. Can someone please point me in the right...
1
by: sk.rasheedfarhan | last post by:
Hi , I am using C# I am having 4 classes. like below. public class A { String m_strRuleName; String m_strRuleGuid; // Some member functions. public Object NextItem; }
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
11
by: dolphin | last post by:
Hi All! I have a question that how to call a function just using a string. For example There is a .cpp file named a.cpp.There are some functions::fun1() fun2() fun3(). I have another fucntion...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.