Help with socket address errno 10049

This is the place for queries that don't fit in any of the other categories.

Help with socket address errno 10049

Postby DarkMage64 » Sun Mar 17, 2013 8:15 pm

Hello,

I'm having trouple with my ddns update script *windows* . I get an error at bind for the socket address and port. Though, I suspect it's telling me an incorrect addresss. However, I look up the sites address and port, which needs to be used. Not sure how to fix this issue either.
Code: Select all
import os
import urllib2
import hashlib
import myip
import threading
import socket
from struct import *
class DDNS_API ( threading.Thread) :
   def __init__(self):
      threading.Thread.__init__( self )
      nkey = hashlib.sha1('lazycat1990|fD2bsCRu')
      self.key = nkey.hexdigest()
      self.externIp = None
   def update(self):
      self.externIp  = myip.get()
      message = """<xml><item><host>ftpcat.spacetechnology.net</host>""" + "<address>" + self.externIp + "</address>" + """<url>
              http://freedns.afraid.org/dynamic/update.php?VVVWMUZhMzFVMVVBQUNsdFVUUUFBQUFFOjkyMTI4NDA=</url>
              </item></xml>"""
      self.data = pack('ss',self.key,self.message)
   def run(self):
      oldexternIp = None
      for socket_info in socket.getaddrinfo("freedns.afraid.org", 8080 , socket.AF_INET, socket.SOCK_STREAM):
         (family, type, prototype, name, socket_address) = socket_info
      s = socket.socket(family,type,prototype)
      s.bind(socket_address)
      s.listen( 5 )
      while True :
         if oldexternIp == None :
            self.update()
            c , addr = s.accept()
            print 'got connection from' , addr
            c.send( self.data )
            c.close()
            oldexternIp = self.externIp
         elif oldexternIp != self.externIp :
            self.update()
            c , addr = s.accept()
            print 'got connection from' , addr
            c.send( self.data )
            c.close()
            oldexternIp = self.externIp
         else :
            print "no update : same external IP "
            
         
      
if  __name__ == "__main__":
   ddns = DDNS_API()
   ddns.start()
   
   

DarkMage64
 
Posts: 2
Joined: Sun Mar 17, 2013 8:09 pm

Re: Help with socket address errno 10049

Postby snippsat » Mon Mar 18, 2013 1:37 am

Code: Select all
>>> s = socket.socket(family,type,prototype)
>>> socket_address
('204.140.20.22', 8080)
>>> s.bind(socket_address)
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python27\lib\socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 10049] Den forespurte adressen er ikke gyldig i konteksten
>>> s.bind(("0.0.0.0", 999))
>>>

If you are behind a router you cannot bind to its IP address, because it is not one of your IP addresses.
Specify the IP of one of your interfaces (Eg, your public IP, or 127.0.0.1 for localhost), or use "0.0.0.0" to bind to all interfaces
If your router is configured correctly, binding to "0.0.0.0" should allow you to access from outside.
If you enable port forwarding, the data packet for the ports will be sent to your computer as there were no router in between.
User avatar
snippsat
 
Posts: 215
Joined: Thu Feb 21, 2013 12:04 am

Re: Help with socket address errno 10049

Postby DarkMage64 » Mon Mar 18, 2013 2:22 am

is it possible to connect instead of mind to the external address? I do not have access to the router.
DarkMage64
 
Posts: 2
Joined: Sun Mar 17, 2013 8:09 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests