Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. connected to the internet or not ??

connected to the internet or not ??

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tamimi Code
    wrote on last edited by
    #1

    HI I have a problem which is I need to know if I am connected to the internet or not... how I could do this through the code so please help me Tamimi - Code

    L 1 Reply Last reply
    0
    • T Tamimi Code

      HI I have a problem which is I need to know if I am connected to the internet or not... how I could do this through the code so please help me Tamimi - Code

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use TcpClient :

      try
      {
      System.Net.Sockets.TcpClient tcpClient = new System.Net.Sockets.TcpClient();
      tcpClient.Connect("www.microsoft.com", 80);

      Console.WriteLine("Connected to internet");
      

      }
      catch(Exception ex)
      {
      Console.WriteLine("Not connected to internet");
      }

      T 1 Reply Last reply
      0
      • L Lost User

        Use TcpClient :

        try
        {
        System.Net.Sockets.TcpClient tcpClient = new System.Net.Sockets.TcpClient();
        tcpClient.Connect("www.microsoft.com", 80);

        Console.WriteLine("Connected to internet");
        

        }
        catch(Exception ex)
        {
        Console.WriteLine("Not connected to internet");
        }

        T Offline
        T Offline
        Tamimi Code
        wrote on last edited by
        #3

        its does not work , iam connected through a LAN. does this mean anything ?? thank you Tamimi - Code

        L A 2 Replies Last reply
        0
        • T Tamimi Code

          its does not work , iam connected through a LAN. does this mean anything ?? thank you Tamimi - Code

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          That code works only if you are connected directly to internet. If you have a proxy, then you must search for an article in codeproject about using TcpClient with Proxy or WebRequest using Proxy.

          1 Reply Last reply
          0
          • T Tamimi Code

            its does not work , iam connected through a LAN. does this mean anything ?? thank you Tamimi - Code

            A Offline
            A Offline
            Aaron Dilliard
            wrote on last edited by
            #5

            If you are connected via LAN, then you should always be connected, unless you only have a local INTRANET, which would explain why you couldnt get through. The code supplied would be a valid way to check for connection, however. Aaron

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups