python中的IPV6套接字设计

时间:2014-06-08 06:07:18

标签: python windows ipv6

我为IPV4套接字写了一段时间:

    h = self.cb.get()
    t = self.text.get()
    sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
    try:
        sock.connect((h, 5554))
        sock.sendall(bytes(t,'ascii'))
        if self.addr_append(h) == 0: 
            self.cb['values'] = self.cb['values'] + tuple([h])
    except:
       print('gui socket send/connect: ',sys.exc_info()[0], " > ",sys.exc_info()[1])
    finally:
        sock.close()

带错误信息:

  

> [WinError 10051]套接字操作是   试图建立一个无法访问的网络

使用IPV4封装(即:: ffff:IPV4 ADDRESS)我收到错误:

  

> [WinError 10049]请求的地址不是   在其上下文中有效

我认为第二个错误是因为Windows不喜欢我对IPV4到IPV6的兼容性设置,但是,这并不能解释为什么它不能解决第一种情况。我是否错误地实施了IPV6?它适用于IPV4。

编辑:我把字符放在了:: ffff:意外的URL注释中。

更新:

我尝试了socket.create_connection,我仍然得到:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
    return self.func(*args)
  File "C:\Users\VMWare\Desktop\Attack.py", line 49, in buttonClick
    sock = socket.create_connection((h, 12839))
  File "C:\Python33\lib\socket.py", line 435, in create_connection
    raise err
  File "C:\Python33\lib\socket.py", line 426, in create_connection
    sock.connect(sa)
OSError: [WinError 10049] The requested address is not valid in its context

我想我现在就放弃这个并回到它,除非有人有其他想法。

0 个答案:

没有答案