Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI VC++
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 10-Jul-11 20:17pm
Edited 10-Jul-11 20:18pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Ashish Tyagi 40 at 11-Jul-11 9:54am
   
good link, my 5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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...)

<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="5;url=http://www.the-domain-you-want-to-redirect-to.com"></meta></head>
<body>
Optional page text here.
this site is blocked and you are redirection to codeproject.com
</body>
</html>

 
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 | Wink | ;-)
  Permalink  
Comments
kadvanimayur at 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 at 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 at 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 at 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...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="5;url=http://www.codeproject.com"></meta></head>
<body>
Optional page text here.
This site is blocked and you are redirecting to
www.codeproject.com in 5 seconds
</body>
</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
  Permalink  
v6
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

i got NtTdiapi to get system level access and block the request on the computer itself and redirect that request..
  Permalink  
Comments
Ashish Tyagi 40 at 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)

  Print Answers RSS
0 OriginalGriff 475
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 219
4 Mathew Soji 160
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 14 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100