Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to restrict access to certain ip ranges

Reply
Thread Tools

how to restrict access to certain ip ranges

 
 
puzzlecracker
Guest
Posts: n/a
 
      11-11-2006
Let's say, I only allow ips in 128.X.X.X/16 and 160.X.0.0. blocks to
access my webserver. How to restrict it..... what api and stratagy to
be used?

I am thinking of putting InetAddres's to HashMap of 128.X.X.0
-128.X.X.255.255 into hashmap and then see if it is there. similarly
for 160*

thanks

 
Reply With Quote
 
 
 
 
as4109@wayne.edu
Guest
Posts: n/a
 
      11-11-2006
puzzlecracker ha escrito:
> Let's say, I only allow ips in 128.X.X.X/16 and 160.X.0.0. blocks to
> access my webserver. How to restrict it..... what api and stratagy to
> be used?


First of all, you may find the following static function useful:

public static int aton(InetAddress ia) {
if (ia==null) return 0;
if (ia instanceof Inet4Address) {
byte[] a = ia.getAddress();
return ((a[0]<<24)
+ ((a[1]&0xFF)<<16)
+ ((a[2]&0xFF)<<
+ (a[3]&0xFF) );
} else {
/* (it's an IPv6 address...return '0' or throw an error or
whatever) */
}}

Given that function, you could check for such conditions with
expressions like

( ntoa(socket.getSocketAddress().getAddress())
& ntoa(new Inet4Address("255.0.0.0") ) == new
Inet4Address("160.0.0.0")

If you just want to determine if an address is "loopback" or
"multicast", you should probably use InetAddress.isLoopbackAddress()
and InetAddress.isMulticastAddress() instead.

--
DLL

 
Reply With Quote
 
 
 
 
Brandon McCombs
Guest
Posts: n/a
 
      11-12-2006
puzzlecracker wrote:
> Let's say, I only allow ips in 128.X.X.X/16 and 160.X.0.0. blocks to
> access my webserver. How to restrict it..... what api and stratagy to
> be used?
>
> I am thinking of putting InetAddres's to HashMap of 128.X.X.0
> -128.X.X.255.255 into hashmap and then see if it is there. similarly
> for 160*
>
> thanks
>


why aren't you implementing that type filter on the network itself
instead of in the application? IP filtering is the job of the network
or at least of software meant to manage that type of thing.
 
Reply With Quote
 
Greg R. Broderick
Guest
Posts: n/a
 
      11-12-2006
"puzzlecracker" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> Let's say, I only allow ips in 128.X.X.X/16 and 160.X.0.0. blocks to
> access my webserver. How to restrict it..... what api and stratagy to
> be used?


Far easier to use something like iptables to accomplish this. I'm sure that
the apache webserver also has some way to permit/deny connections from
specified hosts, but am not an apache expert.

Why reinvent the wheel?

Cheers
GRB

--
---------------------------------------------------------------------
Greg R. Broderick http://www.velocityreviews.com/forums/(E-Mail Removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How-to restrict traffic exiting VPN tunnel to certain hosts / ports?? ponga Cisco 5 07-01-2009 06:25 PM
XSD: restrict number of elements with certain attribute value Joshua Mostafa XML 4 05-11-2007 01:30 AM
How to restrict lenght of entry widget to certain number of character Michael Onfrek Python 7 06-02-2005 02:02 PM
restrict access to Web Service to certain client applications Athen ASP .Net Web Services 2 08-11-2004 04:30 PM



Advertisments