954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Block port 80 programatically

Hi there,
I need to block port 80 (HTTP for internet). Is there a way to block give socket?
Thanks!

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

I'm not sure you understand ports entirely, I couldn't gather that from your post.
To clarify;
Your computer won't make the outgoing connection on port 80. It will choose some random high number port. Port 80 is the INBOUND port for a HTTP server, but it doesn't necessarily have to be port 80. I could tell my browser to go to port 3001 and if a web server was running there it would give me back HTML.

In most cases your best bet is to install a firewall (which can block inbound and outbound traffic depending on its destination). If you need to do this programatically then I suggest google searching on how to build a firewall. (It will involve packet sniffing) =)

Ketsuekiame
Master Poster
752 posts since May 2010
Reputation Points: 349
Solved Threads: 107
 

Aha, you're right!
I was reading this and found that I was talking as if I wan't to block the server. So now the question changes to HOW TO CODE SIMPLE PROXY SERVER That block internet?

Thanks

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

When you say block the internet, what exactly do you want? The internet is an International Network and does not solely consist of Websites. (example; Voice Over IP, FTP, SMTP etc.)

What is the final goal of what you wish to achieve? Please describe it in detail and I'll try and provide you with the best way to go about it.

EDIT: If you truly wish to block the internet, write an application or script that removes the default gateway from the network adapter configuration. This will effectively "block" outbound connections to the internet.

Ketsuekiame
Master Poster
752 posts since May 2010
Reputation Points: 349
Solved Threads: 107
 

I was discussing with a friend and he suggested that I block protocol (HTTP).
Is there a way to do that?

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

Yes, but again, you need to consider what the final goal is. There are plenty of free firewall applications out there that will do what you want.

If you want to go and do this yourself there will be a rather steep learning curve.

In order to do what you ask you will need to intercept all packets coming from the machine, decode them, find which protocol they use and then filter out all the HTTP traffic.

To get you started, here's a handy link

Ketsuekiame
Master Poster
752 posts since May 2010
Reputation Points: 349
Solved Threads: 107
 

Ok here is what I want to achieve. I need to block all Internet traffic, Emails (SMTP), and FTPs I should be able to re-enable it also programatically. Your method of removing gateway seems good. will you explain a little bit?

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

Ok, there's a one line command you can use to remove the gateway from the network adapter (which can be done from the command prompt):
netsh interface ip set address local static gateway=none

Ketsuekiame
Master Poster
752 posts since May 2010
Reputation Points: 349
Solved Threads: 107
 

And how do you re-enable it?

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

Is this disable all port or it is used to close port 80 only????

sheva249
Newbie Poster
12 posts since Jan 2010
Reputation Points: 9
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: