Ulf Dittmer wrote:Oh, it's not the Java process starting the connections? So what you're talking about is a proxy. Why do you want to write your own? There are any number of filtering proxies out there, even open source ones written in Java, if that's what you want to use.
Ulf Dittmer wrote:Can you describe in words what that code is supposed to be doing? Especially, are you trying to block outgoing connections or incoming connections? "Blocking a web site" only makes sense for outgoing connections (because incoming connections are not tied to web sites, they're tied to IP addresses), but hard to tell from the code without knowing what it does.
Ulf Dittmer wrote:The code doesn't seem to accept or monitor either incoming or outgoing connections, so I'm not sure how it could be blocking anything...?
What is the underlying problem you're trying to solve?
Ulf Dittmer wrote:That's not what this code does. As Henry explained, it blocks any process from binding to port 80 - thus no process (in particular no HTTP server, since that's what generally uses port 80) can serve anything on port 80 on that machine.
That is entirely unrelated to which ports on other machines any process (like a web browser) can access from that machine. The inbound port is not the same as the outbound port.
Coding something is not the right way to go about this. Either block outgoing HTTP connections from this machine at your network router (or switch or firewall), or use iptables (on *nix) or the firewall built into Windows to block this kind of traffic.
Paul Clapham wrote:I'm guessing that when you say
when i now try to access http:// sites on the same computer where i have blocked port 80
You really mean
when i now try to access http:// sites from the same computer where i have blocked port 80
Or are these http:// sites really hosted on the computer where you blocked port 80?
Henry Wong wrote:
ritesh thakur wrote:
I am using this code to block a port.
It says port has been blocked. but for eg. if I block port port 80, http sites are opening, while http:// sites work on port 80.
And technically, this isn't blocking a port. The application is basically binding to a local port, which disallows anyone else from using that same port. Blocking a port is selective, allowing certain clients to use the service, while blocking others from getting to the service. Since the application uses the port, the service can't use it. You can achieve the same affect by just not starting the service.
Paul Clapham wrote:Hi ritesh, welcome to the Ranch!
Your post is a little unclear to me: did you mean to say that you tried to block port 80 on your computer by running that code you posted, and then you found that connecting to HTTP sites on some other computer that you could still do that?