Changeset 1337 for seattle/trunk

Show
Ignore:
Timestamp:
02/18/09 21:45:53 (8 years ago)
Author:
justinc
Message:

getmyip fallback to using TCP for Windows Mobile

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • seattle/trunk/repy/emulcomm.py

    r813 r1337  
    434434   
    435435  s.close() 
     436 
     437 
     438  if myip == '' or myip == '0.0.0.0': 
     439    # It's possible on some platforms (Windows Mobile) that the IP will be 
     440    # 0.0.0.0 even when I have a public IP and google is up.   However, if 
     441    # I get a real connection with SOCK_STREAM, then I should get the real 
     442    # answer.    
     443    # I'll do much the same as before, only using SOCK_STREAM, which  
     444    # unfortunately will actually connect 
     445    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
     446    try: 
     447      s.connect(('google.com', 80)) 
     448    except Exception, e: 
     449      raise e 
     450    (myip, localport) = s.getsockname()  
     451   
     452    s.close() 
     453 
     454  if myip == '' or myip == '0.0.0.0': 
     455    # hmm, SOCK_STREAM failed too.   Let's raise an exception... 
     456    raise Exception, "Cannot get external IP despite successful name resolution.  Sockets do not seem to behave properly" 
     457   
    436458 
    437459  return myip