I want to check whether internet is working or not before proceeding with the desired activity. Is there any activity through i can directly perform this check.
One of the possible way is to go to cmd perform ping and get result another way is to use the following code
"System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()" store value in bool variable and use if else to perform check but every time it return true even if internet connection is not there.
How to resolve internet connection lost issue
Works pretty fine .
Note : I have set the Data Type of my variable Internet to GenericValue
As per my SS1 there is Internet Connection and so it returns = “True” Check System Tray (Bottom Right)
As per my SS1 there is NO Internet Connection and so it returns = “False” Check System Tray (Bottom Right)
Hope this Helps
@prassin6, I really appreciate your help but its not working for me. I would suggest you to try same thing with if else condition. It wont work with that. I tried the way you shared your screen shots. It will give the output which we write in the writeline. Its not correct.
Please disconnect your laptop/PC internet and run the script… you can see “False” message
@rkelchuri yes i tried by disconnecting my laptop still getting the same True message. Check the latest screen shot
It’s perfectly working fine for me… please check your network adopter once… and disable it… and run again.
In your machine, please check your local networks. multiple network connections might be enabled in your machine. NetworkInterface.GetIsNetworkAvailable this will always check the data packet flow. So, if your LAN is connected with a server and getting packets it always presume that you have an active connection and it will return true.
So, disable all your networks (this only possible to disable network adopter) and run the script.
@rishimathur, You can try this !
Might be that’s great
Per Microsoft documentation, this method is checking the network interface rather than packets so there could be scenarios where this returns true and there is no network connectivity: