Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to make small application that will redirect the particular url to another url when my application is running on that pc..
e.g
if i type http://www.yahoo.com
then browser should go to http://www.google.com.
i find a lot but didn't get appropriate answer.
vc++.net and vc++ both suggetion are welcome...
Posted
Updated 25-Mar-19 9:52am
v2

 
Share this answer
 
Comments
Ashish Tyagi 40 11-Jul-11 9:54am    
good link, my 5
I guess you already have that list of blocked sites and you are writing code for block them and redirect to your default redirecting site..

It is a very basic functionality of a standard firewall...

Well for blocking or allowing any site requested from the browser you must capture those request and take action... and i think you already wrote the code for this, it is a firewall program actually. (If you are having problem in writing firewall then ask me)

For redirection there is a HEADER in HTTP specification called LOCATION you need to set this header by your desired redirecting site like "www.codeproject.com" in your response.

Otherwise you can use meta redirect. (Which is easier way...)



<title>Your Page Title


Optional page text here.
this site is blocked and you are redirection to codeproject.com




Here 5 indicates how many seconds you want to wait before redirect, meanwhile you can show a message that, this site is blocked and you are redirection to codeproject.com


Good Luck Wink | ;-)
 
Share this answer
 
Comments
kadvanimayur 11-Jul-11 4:28am    
Actually i m not too much experianced...so can you give me code sample of firewall?
and by the way thank you..
Ashish Tyagi 40 11-Jul-11 4:44am    
ha aha ha ... No problem...
First tell me do you know something about socket programming. It is all about it...

Reply first, .. then i will tell you how web browser works how to make http proxy and firewall..
kadvanimayur 11-Jul-11 4:58am    
ya. i worked with socket programming and multithreading as well.. but i don't know how to work with internet..
Ashish Tyagi 40 11-Jul-11 6:48am    
Hey If you know about both of these, then you have done half of your work for rest, please refer my another post below this...
Ok all you need-
1. Configure web browser to connect internet through your program. If you are using internet explorer then Goto tools internet option Connection LAN setting check "use a proxy for your LAN and put 127.0.0.1; in place of Address: and 8080 (or whatever you want) as port no. After this when you click on any link or go to any address then your browser will attempt to make a connect on IP:PORT you configured.
2. Create a server socket and start listening on port 8080 (or what ever you configured). Accept connect from web browser and read all data from client socket (It is data sent by web browser), now you have a HTTP request. for reading this 4k buffer is sufficient.
3. Now parse this request and get the value of HOST: header it must look like "Host: www.google.co.in" (read HTTP specification for the HTTP request format). Hint for parse it look for the index of ;host:" or "Host:" or "HOST:" and copy data starting from Host: and till the "\r\n". Trim the content.
And now you got the desired host name.
4. Now you have 2 cases
A. This host name is in your block list.
What to do :-Take these lines into a buffer

<html><br />
<head><br />
<title>Your Page Title</title><br />
<meta http-equiv="REFRESH" content="5;url=http://www.codeproject.com"></meta></head><br />
<body><br />
Optional page text here.<br />
This site is blocked and you are redirecting to<br />
www.codeproject.com in 5 seconds<br />
</body><br />
</html>


and write that buffer to the client socket (socket for browser). Now browser will redirect page to www.codeproject.com in 5 seconds.

B. This host name is in your block list.
What to do :- create a client TCP socket connect to the host which you just parsed write the HTTP request to it and read the response. now write this response to the socket for web browser and browser will render the page.



If you found any difficulty to understand or implement it feel free to ask and once you write basic program then i will tell you about some design related optimization
 
Share this answer
 
v6
i got NtTdiapi to get system level access and block the request on the computer itself and redirect that request..
 
Share this answer
 
Comments
Ashish Tyagi 40 14-Jul-11 12:13pm    
Ok, well good luck with that but, but why you undo the answer Accepted. Any way I all the best for youe learnings. ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900