Work out if an IP address is in an ISP's IP range

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

jaycook
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Jan 31, 2003 7:22 am

Work out if an IP address is in an ISP's IP range

Postby jaycook » Fri Jan 31, 2003 7:27 am

Hi,

How can I work out if an IP address is in an ISP's IP range (e.g. 213.226.0.0 - 213.226.15.255). Does anyone know a simple way of doing this or some example code. Thanks for looking!

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Sat Feb 01, 2003 2:27 pm

You can use

Code: Select all

$ip = getenv(REMOTE_ADDR);

and make whatever you want with that IP

jaycook
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Jan 31, 2003 7:22 am

Postby jaycook » Mon Feb 03, 2003 1:27 am

Thanks but I already know how to get the IP address. What I need to know is how to work out if the IP address is between a specific ISP's IP range e.g. 213.226.1.1 is in the IP range 213.226.0.0 - 213.226.15.255.

Can it be done with a regular expression maybe?

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Mon Feb 03, 2003 1:52 am

you can separete values in the IP an comere that in the circle...

jaycook
New php-forum User
New php-forum User
Posts: 3
Joined: Fri Jan 31, 2003 7:22 am

Postby jaycook » Tue Feb 04, 2003 1:28 am

Sorry but i'm not entirely sure what you mean. Do you have any example code?

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Feb 04, 2003 2:23 am

exemple of code? no! who about algoritm?

123.123.133.133 - this is IP

separete values whith explode or split function

analize values in the loop.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest