PDA

Click to See Complete Forum and Search --> : [RESOLVED] 127.0.0.1 - Counter


Quiver318
Jul 19th, 2009, 12:07 AM
I route many bad sites straight to 127.0.0.1 using my hosts file, and it works out pretty well. Of course while surfing, I never really get any feedback about the sites I have sent into oblivion. I just know they have been skipped.

Would it be as simple as writing code to open 127.0.0.1 and listen on port 80 to count how many sites I have managed to skip, or is it more complex than that? I really just want a counter to see what I have been missing out on. :D

Thanks,

Quiver

chris128
Jul 20th, 2009, 10:30 AM
I dont know if that would work because technically every website you visit is a connection to 127.0.0.1 on port 80... but I guess it depends how windows classes this internally, it may be that windows just classes it as a connection to your LAN IP and therefore you can do as you say and just have something listen on port 80 that does nothing other than add to a counter when a connection is received. I dont know of any other way to do it if that doesnt work though.

Quiver318
Jul 20th, 2009, 10:55 AM
I dont know if that would work because technically every website you visit is a connection to 127.0.0.1 on port 80... but I guess it depends how windows classes this internally, it may be that windows just classes it as a connection to your LAN IP and therefore you can do as you say and just have something listen on port 80 that does nothing other than add to a counter when a connection is received. I dont know of any other way to do it if that doesnt work though.

Thank you kindly for the analysis. I have not had the time to experiement with the idea and have wondered if it was going to be elaborate, like a full blow web server; or if it might be simple.

chris128
Jul 20th, 2009, 12:19 PM
Here's a very basic example I just put together in console app:


Imports System.Net.Sockets

Module Module1

Private Counter As Integer = 0

Sub Main()
Dim TClient As New TcpListener(Net.IPAddress.Parse("127.0.0.1"), 80)
Console.WriteLine("starting...")
TClient.Start()
Console.WriteLine("started.")
Dim exitloop As Boolean = False
Do While ExitLoop = False
TClient.AcceptTcpClient()
Counter += 1
Console.WriteLine(Counter)
Loop

End Sub

End Module

Seems to work fine, each time I try and browse to http://127.0.0.1 it adds to the counter and writes it to the screen :)

dclamp
Jul 20th, 2009, 01:13 PM
Just a little aside, i tested your code, and it works great. Just to play around with it, i changed the IP to 63.236.73.220, which is VBF. and it gave me an error on line TClient.Start().

A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll

chris128
Jul 20th, 2009, 02:24 PM
Of course it did - you cant listen on just any old IP address, it has to be one that is assigned to your PC. 127.0.0.1 is the default loopback address so always refers to your PC and as such is always available to listen on (unless something else is already listening on the port you specify). So what Quiver has done is add entries to his HOSTS file (C:\Windows\System32\Drivers\etc\hosts) so that bad websites that might appear in popups etc are redirected to 127.0.0.1. Which is why I used 127.0.0.1 in my example code, because that is the specific IP he is trying to listen on.

dclamp
Jul 20th, 2009, 02:55 PM
ah i see. That makes sense. :wave: Thanks

Quiver318
Jul 20th, 2009, 04:42 PM
Of course it did - you cant listen on just any old IP address, it has to be one that is assigned to your PC. 127.0.0.1 is the default loopback address so always refers to your PC and as such is always available to listen on (unless something else is already listening on the port you specify). So what Quiver has done is add entries to his HOSTS file (C:\Windows\System32\Drivers\etc\hosts) so that bad websites that might appear in popups etc are redirected to 127.0.0.1. Which is why I used 127.0.0.1 in my example code, because that is the specific IP he is trying to listen on.

The is great! Thanks for your post! :D