How to Detect a Dialup Connection?

原创 2004年10月06日 18:29:00

How to Detect a Dialup Connection?
Author Date Of Submission User Level
Sushila D. Patel 05/15/2003 Intermediate
http://www.c-sharpcorner.com/Code/2003/May/DetectingDialUpConnection.asp

How to detect if the computer is connected to the net using VB.NET (Windows Form)? How to bring up how can bring up the dial-up window so that the user can dial to the net? (FAQ from the newsgroup) 

Introduction: 

In the article we'll see how to check connectivity with internet using VB.NET and if its not connected give the client the flexibility to get connected. 

Snippet: 

To check if there is connection establish to internet we'll write function which returns a boolean value. (true if connected, false if not). We'll need to use the Namespace System.Net. 

Dim webreq As HttpWebRequest
Dim webresp As HttpWebResponse

'Funtion returns tru or false base on the HttpStatusCode
Function checkconnection(ByVal url As String) As Boolean
Dim strurl As String = url
Dim bConnected As Boolean = False
Try
webreq = WebRequest.Create(strurl)
webresp = webreq.GetResponse
If webresp.StatusCode = HttpStatusCode.OK Then
bConnected = True
Else
bConnected = False
End If
Return bConnected
Catch ex As Exception
bConnected = False
Return bConnected
Finally
webresp = Nothing
End Try
End Function

As a part of user interface lets have a Textbox (where the user can enter the URL) and Button control. On click of the button we'll check if the client is connected to internet. 

If not connected we'll bring up the "Network and Dial-Up Connections" (Here we'll use Shell command) 

If connected we'll open the browser window with the URL specified by the client.(We'll use Process class of System.Diagnostics namespace).Here goes the code to be written on button click. 

Dim lNg As Integer
Dim urlString As String = TextBox1.Text
Dim isConnected As Boolean = checkconnection(urlString)
If isConnected Then
System.Diagnostics.Process.Start("iexplore", urlString)
Else
Dim ans As String = MsgBox("Do you want to connect?", MsgBoxStyle.YesNo, "No Connected")
If ans = vbYes Then
lNg = Shell("rundll32.exe shell32.dll,Control_RunDLL ncpa.cpl,,0")
Else
MsgBox("Sorry canot connect you chose no...")
End If
End If

 


Sushila S. Patel, Microsoft .NET MVP

 

 

How to Check if your computer is connected to the Internet?
Author Date Of Submission User Level
Simohamed Attahri 08/25/2003 Beginner
http://www.c-sharpcorner.com/Code/2003/Aug/CheckInternetConnection.asp

How to check if your computer is connected to the internet with C#. It's much more easier that other tutorials I've seen in other sites. Indeed, we're going to use a simple API function InternetGetConnectedState, to return a boolean variable.

This function takes two arguments :

The first one is an integer used with out keyword, that means that after calling the function, the variable will contain an interger that describes the connection state ( use of a modem, use of a proxy, offline mode...). Note that you must refer to www.msdn.com for more information about that.
The second one is a reserved variable that must be set to 0.

In this tutorial, we'll create a class with a static function that returns true if connected and false if not, using our API function in private state.

Check this out :

using System ;
using
System.Runtime ;
using System.Runtime.InteropServices ;

public class InternetCS
{

//Creating the extern function...
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( out int Description, int ReservedValue ) ;

//Creating a function that uses the API function...
public static bool IsConnectedToInternet( )
{

int Desc ;
return InternetGetConnectedState( out Desc, 0 ) ;

}

}


Simohamed Attahri
Simohamed Attahri for help.

 

 

How to detect HTTP connection break

How to detect HTTP connection breakMany a times HTTP connection breaks due to some reasons. The conn...
  • utopia2006
  • utopia2006
  • 2009年06月14日 00:11
  • 795

linux下使用myeclipse报错Could not detect registered XULRunner to use

在linux环境下装了myeclipse,开java是没有什么问题的,但是开jsp却会有个提示The Linux WYSIWYG design panel is still under develop...
  • tsingheng
  • tsingheng
  • 2013年09月15日 19:01
  • 3189

How to detect when the client closes the connection?

Imagine the following scenario: You are writing a server application. Clients send their queries to ...
  • wxqian25
  • wxqian25
  • 2013年10月18日 10:44
  • 436

how to detect VMM using (almost) one CPU instruction

 Red Pill... orJoanna Rutkowskahttp://invisiblethings.org/November 2004Swallowing the Red Pill is mo...
  • iiprogram
  • iiprogram
  • 2008年03月21日 09:20
  • 830

OpenCV - Detect skew angle

refer from http://felix.abecassis.me/2011/09/opencv-detect-skew-angle/ OpenCV Lately I have ...
  • kaka20080622
  • kaka20080622
  • 2015年12月07日 21:33
  • 1114

JavaScript: How to detect that the Internet Connection is foffline

There are a number of ways to do this:AJAX request to your own website. If that request fails, there...
  • kissjob
  • kissjob
  • 2011年05月23日 12:49
  • 352

jdk的设置及安装android studio提示does not point to a valid jvm问题

转自:  http://www.cnblogs.com/huangfr/p/3895343.html
  • primer_programer
  • primer_programer
  • 2014年10月30日 21:48
  • 11246

How to Have a Healthy Relationship

There are reliable tools that can be used to create a healthy relationship, many of which have not b...
  • iloveorchid
  • iloveorchid
  • 2012年04月09日 19:21
  • 982

How TCP Establishes A Connection

TCP Is a Connection-Oriented Protocol TCP opens up a virtual connection between the client and ser...
  • macyang
  • macyang
  • 2009年11月27日 23:45
  • 571

Hadoop学习二(java api调用操作HDFS)

在Ubuntu虚拟机上启动了hadoop后,在windows机器上通过java api方式调用操作hdfs,在使用过程中遇到了一些问题。 首先创建了一个maven项目,pom.xml文件中引入了 ha...
  • wukongbajieheti
  • wukongbajieheti
  • 2017年04月18日 10:55
  • 756
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to Detect a Dialup Connection?
举报原因:
原因补充:

(最多只允许输入30个字)