Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[Tut] Check For Internet Connection

Tutorial #3 - Check For Internet Connection

1. Open Visual Basic, name your project whatever.

2. Add: Label, Button.

[img]http://speedcap.net/img/fac064aefa9a848d534f05f35d0e1e20/4f4de67b.png[/img]

3. Double Click The Button

4. Write:
Code
Dim WebClient As New Net.WebClient 'Declare The WebClient
        Label1.Text = WebClient.DownloadString("http://www.pastn.com/index.php") 'Download the ip string from my site.
        If Label1.Text = "" Then
            MsgBox("No Internet Connection!", MsgBoxStyle.Information) 'Error if no connection
        Else
            MsgBox("Internet Connection Available!", MsgBoxStyle.Information) 'Success if connection!
        End If

Debug, click the button and you should get:

[img]http://speedcap.net/img/fac064aefa9a848d534f05f35d0e1e20/200285cd.png[/img]
That's totaly dumb , dumbest snippet ever
Code
Dim IsConnected = True
  Try
    Dim HE As System.Net.IPHostEntry
    HE = System.Net.Dns.GetHostEntry("www.google.com")
  Catch ex As Exception
    IsConnected = False
  End Try
Let me chck this out thoughh/ thnc
there's also :
Code
If My.Computer.Network.IsAvailable = True Then MsgBox("Connected") Else MsgBox("Not Connected")
Here also
Code
Public Function Connection() As Boolean
  Dim sitetocheck As New System.Uri("http://www.google.com/")
  Dim checkrequest As System.Net.WebRequest
  checkrequest = System.Net.WebRequest.Create(sitetocheck)
  Dim objResp As System.Net.WebResponse
  Try
    objResp = checkrequest.GetResponse
    objResp.Close()
    checkrequest = Nothing
    Return True
  Catch x As Exception
    Return False
  End Try
    End Function

And then use the function in anywhere like this
Code
If Connection() = True Then
    MsgBox("Network connection okey")
  Else
    MsgBox("Networks connection not okey")
End If
Good simple tutorial ryan :) make some more.
(Sep 30, 2011 12:58 AM)revtorus Wrote:  there's also :
Code
If My.Computer.Network.IsAvailable = True Then MsgBox("Connected") Else MsgBox("Not Connected")

I haven't tested it out but wouldn't it just check if the LAN / WLAN is available?
This is just dumb because if there is no internet connection and our application tries to download the string from the .txt file, probably it will give error.

Regards,
HaXoR-
No its not dumb, because when it tries to download it then it will give you "" which means no ip because you are offline.
(Sep 30, 2011 08:20 AM)Sapientia Wrote:  No its not dumb, because when it tries to download it then it will give you "" which means no ip because you are offline.

It is dumb, because there are far more efficient ways.
Thats fine, and i was showing one way you could do this.
(Sep 30, 2011 08:37 AM)Sapientia Wrote:  Thats fine, and i was showing one way you could do this.

If you're going to post an example, make sure its a good one.
I think its a pretty good snippet (Im a beginner)
he didnt say it was ment to be the best way of doing it.
thanks OP :)
Using labels ? 😶
There are shorter and better methods ...
[Image: bmb5MjV.png]

You could also do a Fuction wich Pings something :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by E V OJan 8, 2019 11:08 AM 5 125 Jan 8, 2019 11:08 AM
Last Post: FriendZone
[Shell] by Motioncity13Feb 11, 2016 09:17 PM 4 147 Feb 11, 2016 09:17 PM
Last Post: b00st3d
[.NET] by zetustigerJun 25, 2014 11:45 AM 18 449 Jun 25, 2014 11:45 AM
Last Post: zetustiger