Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Website Blocker

Status
Not open for further replies.

MIB

Programmer
Feb 12, 2000
3
0
0
US
Was wanting to know if there was any source code for a starter program for a website blocker, what i need is it to read from a list of words if that given word is in the list it will not load the website <br>
<br>
<br>
Thanks
 
MIB -<br>
<br>
This is a pretty involved subject that comes up time and time again on the Winsock2 mailing list. The basics are that you have to write a LSP (Layered Service Provider) that intercepts both TCP and UDP packets (both, because of a bug in Microsoft's TCP/IP implmentation). If you want to support Win2K and Win98 as well as NT4 and Win95, you have to write things a bit differently as well.<br>
<br>
Your LSP would have to do the following:<br>
1) Determine if it's a TCP request<br>
2) Determine if it's going to port 80<br>
3) Determine if it's a HTTP request<br>
4) Look at the URL to see if it's allowed, and if it's on the &quot;badsite&quot; list, return a HTTP response saying &quot;You're a naughty boy!&quot;<br>
<br>
I would say that VB is not capable of writing a LSP because they load at boot time, and the runtime requirements for a VB program cannot be met. The reason behind using a LSP in the first place is the end users could install a 3rd-party browser (NetScape, Opera, etc) that could get around any filtering done by a VB app that uses the Internet Explorer OCX.<br>
<br>
Chip H.<br>

 
Chip,<br>
<br>
You could run the VB app on a machine that was configured as a proxy server...<br>
<br>
That way all requests for pages could go through your VB app, not trivial though.<br>
<br>
Mike <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
&gt; That way all requests for pages could go through your VB app, not trivial though. &lt;<br>
<br>
That is one method I hadn't thought of. But like you said, non-trivial.<br>
<br>
Plus, I haven't seen a TCP/IP OCX for VB that scaled to handle large numbers of users like using the Win32 I/O Completion Ports would.<br>
<br>
MIB -- I think you ought to re-think this.<br>
<br>
Chip H.<br>
<br>

 
ok thanks alot for the posts anyway it was an idea :))
 
Just a thought... if you can specify a list of URLs to block or simply want restrict the user to a list of &quot;friendly&quot; URLs you might be able to use the code at <A HREF=" TARGET="_new"> (suggested by member netwalker1).<br>
<br>
<A HREF=" TARGET="_new"> retrieves the URL for the current page. Save that value and check to see if it is on a list of restricted pages (or fails to appear on a list of approved pages).<br>
<br>
If it fails the test use the code in <A HREF=" TARGET="_new"> to return the user to the previous page.<br>
<br>
It isn't exactly what you were looking for but it might be a way to start.<br>
<p> <br><a href=mailto: > </a><br><a href= Vorpalcom home page</a><br>Send me suggestions or comments on my current software project.
 
Chip,<br>
<br>
Interesting point about scaling a TCP ocx.<br>
<br>
What do you call large numbers of connections? I have a 24x7 VB app that handles 200 ish TCP connections without trouble; uses MS Winsock.<br>
<br>
Tell me more...<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Well, while you guys were arguing bigger and better things, I wrote a little app to keep users from browsing beyond the straight-and-narrow. (Haven't tried it on NT.)<br>
Corporate users waste a lot of time on the Internet and, sometimes, end up looking at something that doesn't improve the quality of their work.<br>
Mike, I know you are an exception. Chiph, you were partially correct in your first post in this thread (but it really isn't that difficult). MIB, you might reconsider your approach (don't worry about the words, if a page disappears, the users can't read the words or look at the pictures).<br>
<p> <br><a href=mailto: > </a><br><a href= Vorpalcom home page</a><br>Send me suggestions or comments on my current software project.
 
Mike -<br>
<br>
I don't have any hard numbers as to what the MS Winsock OCX can handle. Just looking at how a programmer would have to respond to it's events gives me a big clue that it doesn't scale.<br>
<br>
And by scale, I mean large numbers of client connections (500 and up). You can always throw hardware at a scalability problem, but I think you & I both would prefer to solve it through more efficient algorithms (job security, you know!).<br>
<br>
Have you worked with IOCP's before? They're not that bad, once you know a few tricks. The key is to use a couple of structures like this:<br>
<br>
typedef enum LAST_IO_OPERATION_tag {<br>
&nbsp;&nbsp;&nbsp;&nbsp;ClientIoInit,<br>
&nbsp;&nbsp;&nbsp;&nbsp;ClientIoRead,<br>
&nbsp;&nbsp;&nbsp;&nbsp;ClientIoWrite<br>
} LAST_IO_OPERATION, *PLAST_IO_OPERATION;<br>
<br>
typedef struct CLIENT_CONTEXT_tag {<br>
&nbsp;&nbsp;&nbsp;&nbsp;SOCKET&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket;<br>
&nbsp;&nbsp;&nbsp;&nbsp;LAST_IO_OPERATION&nbsp;&nbsp;&nbsp;&nbsp;LastClientIo;<br>
&nbsp;&nbsp;&nbsp;&nbsp;OVERLAPPED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Overlapped;<br>
&nbsp;&nbsp;&nbsp;&nbsp;BYTE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byReadBuffer[READBUFFER_SIZE];<br>
&nbsp;&nbsp;&nbsp;&nbsp;WSABUF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wsaBuf;<br>
&nbsp;&nbsp;&nbsp;&nbsp;//... Other app specific stuff ...//<br>
} CLIENT_CONTEXT, *PCLIENT_CONTEXT;<br>
<br>
to the CreateIoCompletionPort call.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;pClientContext-&gt;LastClientIo = ClientIoInit;<br>
&nbsp;&nbsp;&nbsp;&nbsp;// Associate the new socket with the existing Completion Port<br>
&nbsp;&nbsp;&nbsp;&nbsp;hCompletionPort = CreateIoCompletionPort((HANDLE)s, hCompletionPort, (DWORD) pClientContext, 0);<br>
<br>
Then when your code returns from GetQueuedCompletionStatus (in your worker threads), the pClientContext structure gets passed along with all the info you need. You just look at the LastClientIo field to figure what kind of request it was (initialization, read, write), and handle it.<br>
<br>
<br>
Alt255 - <br>
<br>
Which part was I partially correct about? In writing a LSP, the fundamentals are easy. The hard part is all the border conditions -- what to do about UDP packets, how to handle installation, re-installation issues, etc.<br>
<br>
The installation issues comes up pretty frequently too. Someone will write a LSP, then the user will install the latest whiz-bang internet software, and the LSP gets relocated in the call chain, and stops working.<br>
<br>
Chip H.<br>

 
MIB's original question asked for a simple way to get started on a blocker. It seemed, simple to use some ordinary API functions;<br>
RasEnumConnections and RasGetConnectStatus to check the internet connection. EnumWindows, GetClassName, SendMessage and GetWindowsText to retrieve the URL. ShellExecute to return to the previous URL if the current one does not appear on a list of approved sites.<br>
<br>
MIB could even check for &quot;naughty&quot; words on a page. This actually works, 'though I wouldn't recommend it because it's such a cheap and inefficient way of finding words on a page (Mike and ChipH will undoubtedly point out 39 <b>good</b> ways to copy the focus window to the clipboard).<br>
<br>
OldClbd$=Clipboard.GetText&nbsp;&nbsp;&nbsp;&nbsp;'save the contents of the clipboard<br>
SendKeys &quot;^a&quot;, True&nbsp;&nbsp;&nbsp;&nbsp;'select all on the page with focus<br>
SendKeys &quot;^c&quot;, True&nbsp;&nbsp;&nbsp;&nbsp;'put the text on the clipboard<br>
SendKeys &quot;{TAB}&quot;&nbsp;&nbsp;&nbsp;&nbsp;'deselect all<br>
Clbd$=UCase$(Clipboard.GetText)&nbsp;&nbsp;&nbsp;&nbsp;'put the upper case clipboard in a string<br>
For Rep = 1 to UBound(NaughtyWordList)<br>
'check for naughty words<br>
&nbsp;&nbsp;&nbsp;&nbsp;If InStr(Clbd$, NaughtyWordList(Rep)) Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Page contains naughty words&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;End If<br>
Next<br>
Clipboard.SetText OldClbd$&nbsp;&nbsp;&nbsp;&nbsp;'restore the old clipboard contents<br>
<br>
It just didn't seem necessary to use an OCX and, frankly, you guys are talking about things that are a little over my head. I'm sorry I opened my mouth.<br>
With that, I respectfully bow out of this discussion.<br>
<p> <br><a href=mailto: > </a><br><a href= Vorpalcom home page</a><br>Send me suggestions or comments on my current software project.
 
&gt; It just didn't seem necessary to use an OCX and, frankly, you guys are talking about things that are a little over my head. I'm sorry I opened my mouth. With that, I respectfully bow out of this discussion. &lt;<br>
<br>
Sorry -- got a little carried away. Besides, you know what they say -- &quot;Thread drift happens&quot;!<br>
<br>
Looking over your code, it actually seems pretty simple -- snag the URL by copying it into the clipboard, check it, and if it's not on a &quot;bad&quot; list of any kind, send it on through. Maybe this was all MIB had in mind, back on 13Mar00.<br>
<br>
And then I had to go and spoil it all by building it into a massive project that accounts for every possible condition. I'm such a geek. &lt;sob&gt;<br>
<br>
Chip H.<br>
&lt;g&gt;<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top