Results 1 to 8 of 8

Thread: [RESOLVED] 127.0.0.1 - Counter

  1. #1

    Thread Starter
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    Resolved [RESOLVED] 127.0.0.1 - Counter

    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.

    Thanks,

    Quiver

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: 127.0.0.1 - Counter

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    Re: 127.0.0.1 - Counter

    Quote Originally Posted by chris128 View Post
    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.

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: 127.0.0.1 - Counter

    Here's a very basic example I just put together in console app:

    vb.net Code:
    1. Imports System.Net.Sockets
    2.  
    3. Module Module1
    4.  
    5.     Private Counter As Integer = 0
    6.  
    7.     Sub Main()
    8.         Dim TClient As New TcpListener(Net.IPAddress.Parse("127.0.0.1"), 80)
    9.         Console.WriteLine("starting...")
    10.         TClient.Start()
    11.         Console.WriteLine("started.")
    12.         Dim exitloop As Boolean = False
    13.         Do While ExitLoop = False
    14.             TClient.AcceptTcpClient()
    15.             Counter += 1
    16.             Console.WriteLine(Counter)
    17.         Loop
    18.  
    19.     End Sub
    20.  
    21. 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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: 127.0.0.1 - Counter

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

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

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: 127.0.0.1 - Counter

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: 127.0.0.1 - Counter

    ah i see. That makes sense. Thanks

  8. #8

    Thread Starter
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    Re: 127.0.0.1 - Counter

    Quote Originally Posted by chris128 View Post
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width