Jump to content

Network Status


Recommended Posts

I'm having trouble with figuring out how to simply check whether my local area connection is active before executing the rest of my script.

If the network cable is plugged in, then do this

if it's not, then send error message "plug the cable in".

I'd rather not have to call the adapters properties to text and read it back in. Something like

If NetworkStatus = True

Do my script

if NetworkStatus = False

"Plug in the doggone network cable!"

My problem is figuring out the best way to check the status! Any ideas?

Link to comment
Share on other sites

Hm. So something like:

If _IsInternetConnected = 1 Then

$answer = MsgBox(0, "Please make sure your network cable is connected, then restart IP Change.")

Exit

EndIf

Func _IsInternetConnected()

Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')

If @error Then

Return SetError(1, 0, False)

EndIf

Return $aReturn[0] = 0

EndFunc ;==>_IsInternetConnected

Actually, I get an error. Error parsing function call.

*sigh* been a long day, brain just isn't working!

Link to comment
Share on other sites

  • Moderators

Notice the header on the script, it returns True or False.

Edit: Try something like this:

If _IsInternetConnected() = True Then
  MsgBox(0, "", "Connected")
Else
  MsgBox(0, "", "Not Connected")
EndIf
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Notice the header on the script, it returns True or False.

So? ... "In AutoIt there is only one datatype called a Variant" ... :)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

This would be suffice as you don't need to check for True or False exclusively.

If _IsInternetConnected() Then....

If Not _IsInternetConnected() Then ...

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

With Windows 7, all is exactly as it should be. With XP, it comes up as false whether there's a network connection or not. Any ideas?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=wi0064-64.ico
#AutoIt3Wrapper_Outfile=IP Change.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; OS: XP, Windows 7
; Author: Ken Stillings
;

#include 

;declaring the variables needed for user input
Global $IP = ""
Global $SN = ""
Global $GW = ""
Global $Error = ""

;creating the GUI and related buttons
GUICreate("CBE IP Change", 260, 460)

GuiCtrlCreateLabel(" (Click to set for ASA)", 5, 15, 125, 30)

$ASAButton = GUICtrlCreateButton("ASA", 135, 5, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Sets IP to" & @cr &"192.168.31.200"& @cr &"255.255.255.0"& @cr &"192.168.31.31")

GuiCtrlCreateLabel(" (Click to set for SFC)", 5, 50, 125, 30)
$SFCButton = GUICtrlCreateButton("SFC", 135,40, 120, 30)
;the following line creates a tooltip
GuiCtrlSetTip(-1, "Sets IP to" & @cr & "169.254.196.200"& @cr &"255.255.255.0")

GuiCtrlCreateLabel("(Click to set for 3xLOGIC)", 5, 85, 125, 30)
$3XButton = GUICtrlCreateButton("3xLOGIC", 135,75, 120, 30)
;the following line creates a tooltip
GuiCtrlSetTip(-1, "Sets IP to"& @cr & "10.1.1.250"& @cr &"255.255.255.0")

GuiCtrlCreateLabel(" (Click to set Custom IP)", 5, 120, 125, 30)
$CUSTButton = GUICtrlCreateButton("Custom", 135,110, 120, 30)
;the following line creates a tooltip
GuiCtrlSetTip(-1, "This button allows you to enter"& @cr & "your own IP information")

GuiCtrlCreateLabel("(Click to set for Standard)", 5, 155, 125, 30)
$STDButton = GUICtrlCreateButton("Standard", 135,145, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Restores your IP to DHCP which"& @cr &"pulls the IP from the router")

GuiCtrlCreateLabel(" (Click to ping Sapphire)", 5, 190, 125, 30)
$PNGSapphire = GUICtrlCreateButton("Sapphire", 135,180, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Pings the Sapphire"& @cr &"IP 192.168.31.11")

GuiCtrlCreateLabel(" (Click to ping HPV-20)", 5, 225, 125, 30)
$PNGhpv = GUICtrlCreateButton("HPV-20", 135,215, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Pings the HPV-20"& @cr &"IP 192.168.31.1")

GuiCtrlCreateLabel(" (Click to ping Router)", 5, 260, 125, 30)
$PNGrouter = GUICtrlCreateButton("ROUTER", 135,250, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Pings the router at "& @cr &"IP 192.168.31.31")

GuiCtrlCreateLabel("(Run IPCONFIG /Release)", 5, 295, 130, 30)
$IPrelease = GUICtrlCreateButton("/RELEASE", 135,285, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Runs the"& @cr &"IPCONFIG /release command")

GuiCtrlCreateLabel(" (Run IPCONFIG /Renew)", 5, 330, 125, 30)
$IPrenew = GUICtrlCreateButton("/RENEW", 135,320, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Runs the"& @cr &"IPCONFIG /renew command")

GuiCtrlCreateLabel(" (Run IPCONFIG /All)", 5, 365, 125, 30)
$IPall = GUICtrlCreateButton("/ALL", 135,355, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Runs the IPCONFIG /ALL"& @cr &"command, showing current"& @cr &"IP configuration")

GuiCtrlCreateLabel("(Run RubyCommOptions)", 5, 400, 125, 30)
$IPrco = GUICtrlCreateButton("RubyCommOptions", 135,390, 120, 30)

;the following line creates a tooltip
GuiCtrlSetTip(-1, "Calls up the RubyCommOptions program")

$EXITButton = GUICtrlCreateButton("Exit", 135,425, 120, 30)
;the following line creates a tooltip
GuiCtrlSetTip(-1, "This button exits the program")

; GUI MESSAGE LOOP
GuiSetState()
If not _IsInternetConnected() Then
$answer = MsgBox(0, "Error", "Please make sure your network cable is connected, then restart IP Change.")
Exit
EndIf
While 1
$msg = GUIGetMsg()


Select
Case $msg = $ASAButton
Run ('C:\Windows\System32\netsh.exe')
sleep (1000)
send ('interface IP set address name="Local Area Connection" source=static 192.168.31.200 255.255.255.0 192.168.31.31 1+{enter}')
sleep (1000)
send ('exit+{enter}')
sleep (1000)
$answer = MsgBox(0, "IP Address", "Your IP address is set.")

Case $msg = $SFCButton
Run ('C:\Windows\System32\netsh.exe')
sleep (1000)
send ('interface ip set address name="Local Area Connection" source=static 169.254.196.200 255.255.255.0+{enter}')
sleep (1000)
send ('exit+{enter}')
sleep (1000)
$answer = MsgBox(0, "IP Address", "Your IP address is set.")

Case $msg = $3xButton
Run ('C:\Windows\System32\netsh.exe')
sleep (1000)
send ('interface ip set address name="Local Area Connection" source=static 10.1.1.250 255.255.255.0+{enter}')
sleep (1000)
send ('exit+{enter}')
sleep (1000)
$answer = MsgBox(0, "IP Address", "Your IP address is set.")

Case $msg = $STDButton
Run ('C:\Windows\System32\netsh.exe')
sleep (1000)
send ('interface ip set dns name="Local Area Connection" source=DHCP+{enter}')
sleep (1000)
send ('interface ip set wins name="Local Area Connection" source=DHCP+{enter}')
sleep (1000)
send ('interface ip set address name="Local Area Connection" source=DHCP+{enter}')
sleep (1000)
send ('exit+{enter}')
sleep (500)
$answer = MsgBox(0, "IP Address", "Your IP address is set.")


Case $msg = $CUSTButton
GetIP()
GetSN()
GetGW()
Run ('C:\Windows\System32\netsh.exe')
sleep (1000)
if $GW <>"" then
send ('interface ip set address "Local Area Connection" static ' & $IP & ' ' & $SN &' ' & $GW & ' 1+{enter}')
else
send ('interface ip set address "Local Area Connection" static ' & $IP &' ' & $SN &'+{enter}')
endif
sleep (1000)
send ('exit+{enter}')
sleep (500)
$answer = MsgBox(0, "IP Address", "Your IP address is set.")

Case $msg = $PNGSapphire
Run ('C:\Windows\System32\cmd.exe')
sleep (1000)
send ('ping 192.168.31.11+{enter}')

Case $msg = $PNGhpv
Run ('C:\Windows\System32\cmd.exe')
sleep (1000)
send ('ping 192.168.31.1+{enter}')

Case $msg = $PNGrouter
Run ('C:\Windows\System32\cmd.exe')
sleep (1000)
send ('ping 192.168.31.31+{enter}')

Case $msg = $IPrelease
Run ('C:\Windows\System32\cmd.exe')
sleep (1000)
send ('ipconfig /release+{enter}')

Case $msg = $IPrenew
Run ('C:\Windows\System32\cmd.exe')
sleep (1000)
send ('ipconfig /renew+{enter}')

Case $msg = $IPall
Run ('C:\Windows\System32\cmd.exe')
sleep (1000)
send ('ipconfig /all+{enter}')

Case $msg = $IPrco
Run ('C:Gemcombinrubycommoptions.exe')

Case $msg = $EXITButton
exit
EndSelect
If $msg = $GUI_EVENT_CLOSE Then ExitLoop ;ends the application if the red X is clicked on the gui
Wend

;~~~~~~~~~~~~~~~~~~~

func GetIP()
;remove any information in the variables
$IP = ""

;accepts user input

$IP = InputBox("Enter IP Address", "Please enter the IP address in this format: xxx.xxx.xxx.xxx", "", "", 0,0)
If @Error = 1 then
Exit
endIf
ValidIP($IP)

EndFunc

;~~~~~~~~~~~~~~~~~~~~~
func GetSN()
$SN = "" ;clearing any previous data

$SN = InputBox("Enter Subnet", "Please enter the subnet mask in this format: xxx.xxx.xxx.xxx", "", "", 0,0)
If @Error = 1 then
Exit
EndIf
ValidSN($SN)

EndFunc

;~~~~~~~~~~~~~~~~~~~~~~~~

func GetGW()
$GW = "" ;clearing any previous data

$GW = InputBox("Enter Gateway", "Please enter the gateway in this format: xxx.xxx.xxx.xxx - or leave blank", "", "", 0,0)

If $GW <> "" then
ValidGW($GW) ; only needs to check for validity if field is not left blank.
EndIf

endfunc

;~~~~~~~~~~~~~~~~~~~~~~

func ValidIP($IPcheck)
$arrayIP = StringSplit($IPcheck, ".")

if $arrayIP[0] <> 4 then
msgbox(16, "Error", "Invalid IP range.")
GetIP()
elseif $arrayIP[1] < 1 OR $arrayIP[1] > 255 then
msgbox(16, "Error", "Invalid IP range.")
GetIP()
elseif $arrayIP[2] > 255 then
msgbox(16, "Error", "Invalid IP range.")
GetIP()
elseif $arrayIP[3] > 255 then
msgbox(16, "Error", "Invalid IP range.")
GetIP()
elseif $arrayIP [4]> 255 then
msgbox(16, "Error", "Invalid IP range.")
GetIP()
EndIf

$count = 1
while $count < 5
if (StringIsDigit($arrayIP[$count]) ==0) then
msgbox(16, "Error", "No letters or special characters allowed.")
GetIP()
EndIf
$count = $count +1
wend

endFunc

;~~~~~~~~~~~~~~~~~~~~~~~~
func ValidSN($SNCheck)
$arraySN = StringSplit($SNcheck, ".")

if $arraySN[0] <> 4 then ;the first element in the split array gives the number of elements. If there's more or less than 4 elements (192.168.1, or 192.124.23.1.2) then there is an error.
msgbox(16, "Error", "Invalid Subnet range.")
GetSN()
elseif $arraySN[1] < 1 OR $arraySN[1] > 255 then
msgbox(16, "Error", "Invalid Subnet range.")
GetSN()
elseif $arraySN[2] > 255 then
msgbox(16, "Error", "Invalid Subnet range.")
GetSN()
elseif $arraySN[3] > 255 then
msgbox(16, "Error", "Invalid Subnet range.")
GetSN()
elseif $arraySN[4]> 255 then
msgbox(16, "Error", "Invalid Subnet range.")
GetIP()
EndIf

;the array containing the information from the entry starts at element 1, not 0. Here, we run through a loop looking for non numeric entries.
$count = 1
while $count < 5
if (StringIsDigit($arraySN[$count]) ==0) then
msgbox(16, "Error", "No letters or special characters allowed.")
GetIP()
EndIf
$count = $count +1
wend

endFunc
;~~~~~~~~~~~~~~~~~~~~~~~~
func ValidGW($GWCheck)
$arrayGW = StringSplit($GWcheck, ".")

if $arrayGW[0] <> 4 then
msgbox(16, "Error", "Invalid IP range.")
GetGW()
elseif $arrayGW[1] < 1 OR $arrayGW[1] > 255 then
msgbox(16, "Error", "Invalid IP range.")
GetGW()
elseif $arrayGW[2] > 255 then
msgbox(16, "Error", "Invalid IP range.")
GetGW()
elseif $arrayGW[3] > 255 then
msgbox(16, "Error", "Invalid IP range.")
GetGW()
elseif $arrayGW[4]> 255 then
msgbox(16, "Error", "Invalid IP range.")
GetGW()
EndIf

;the array containing the information from the entry starts at element 1, not 0. Here, we run through a loop looking for non numeric entries.
$count = 1
while $count < 5
if (StringIsDigit($arrayGW[$count]) ==0) then
msgbox(16, "Error", "No letters or special characters allowed.")
GetGW()
EndIf
$count = $count +1
wend

endFunc



Func _IsInternetConnected()
Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
If @error Then
Return SetError(1, 0, False)
EndIf
Return true ;$aReturn[0] = 0
EndFunc ;==>_IsInternetConnected
Link to comment
Share on other sites

Yeh, IsInternetConnected (Vista+)

If XP I would suggest searching around the forum for 'InternetGetConnectedState' (though not very reliable sometimes. See MSDN)

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...