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]
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.
Thats fine, and i was showing one way you could do this.
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 :)
You could also do a Fuction wich Pings something :)
(Feb 10, 2013 12:23 PM)Zombay Wrote:  Lol, this post was actually from 09-30-2011, 08:04 and everyone flames about it now 🤣

You were the one that gravedug it as well as flamed it. It was also flamed right after it was made in 2011, not like it's new that it's flamed now.
Can we please stop posting on this, k thanks guys.
Yeah, close it, I'm getting tired of seeing it in first page every time ...


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