Jump to content

[USB tethering] Waiting for IP address?


Go to solution Solved by littlebigman,

Recommended Posts

Hello,

For some reason, it takes a couple of minutes for my Windows computer to assign an IP address when connecting my Android phone and enabling USB tethering so I can sync data from the phone.

Before I look deeper, is there a better way to wait until USB tethering is alive than looping for up to 2mn AND checking that a valid IP address (192.168.x.y, where x > 0) is assigned?

Pseudo-code:

#include <Constants.au3>
#include <MsgBoxConstants.au3>

;TODO: Wait until USB tethering valid: any IP 192.162.x.y where x > 0
While CURRTIME < START+2mn AND no right IP in REGEX(@IPAddress1-4)
     Sleep 1000
    Increment time
WEnd

Global $StrFrmt = StringFormat("Add1: %s\r\nAdd2: %s\r\nAdd3: %s\r\nAdd4: %s",@IPAddress1,@IPAddress2,@IPAddress3,@IPAddress4)

MsgBox($MB_OK,"My Ip Addresses:", $StrFrmt)

 

Thank you.

Link to comment
Share on other sites

  • Solution

Unless there's a better way… checking that the third byte in @IPAddress1 changes from 0 to something else seems to work on my 'puter:

#include <Constants.au3>
#include <Date.au3>
#include <MsgBoxConstants.au3>

Opt('MustDeclareVars', 1)

Func CurrTime()
    Return _DateDiff('s', "1970/01/01 00:00:00", _NowCalc())
EndFunc

Func Tethered()
    Local $res = StringRegExp(@IPAddress1,"^192\.168\.(\d+)\.(\d+)$", 1)
    If $res[0] = 0 Then ;Is third byte 0/something else?
        Return False
    Else
        Return True
    EndIf
EndFunc

Local $StartTime = CurrTime()
;Wait 180s/3mn
While (CurrTime() < $StartTime + 180) And Not Tethered()
    ConsoleWrite("@IPAddress1=" & @IPAddress1 & @CRLF)
    Sleep(1000)
WEnd


Local $outcome = (Tethered()) ? "Tethered" : "Not Tethered"
MsgBox($MB_ICONINFORMATION, "Out", $outcome)
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...