2015-11-05 40 views
0

我想從Windows/Linux發送一條消息到我在Ubuntu上創建的IPV6虛擬IP地址。任何人都可以建議這樣做的過程?如何將消息發送到虛擬IPV6地址?

我創建的虛擬IPV6在Ubuntu通過下面的代碼: sudo的IP地址-6 2002年增加:1:1:1 :: 10/64 dev的eth0的

而且,對於發送消息到IPV6我用這Pyhton代碼:

對於客戶:

# Echo client program 
import socket 
import sys 

HOST = '2002:1:1:1::10'  # The remote host 
PORT = 50007    # The same port as used by the server 
s = None 
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM): 
    af, socktype, proto, canonname, sa = res 
    try: 
     s = socket.socket(af, socktype, proto) 
    except OSError as msg: 
     s = None 
     continue 
    try: 
     s.connect(sa) 
    except OSError as msg: 
     s.close() 
     s = None 
     continue 
    break 
if s is None: 
    print('could not open socket') 
    sys.exit(1) 
s.sendall(b'Hello, world') 
data = s.recv(1024) 
s.close() 
print('Received', repr(data)) 

服務器爲:

# Echo server program 
import socket 
import sys 

HOST = '2002:1:1:1::10'    # Symbolic name meaning all available interfaces 
PORT = 50007    # Arbitrary non-privileged port 
s = None 
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,socket.SOCK_STREAM, 0, socket.AI_PASSIVE): 
    af, socktype, proto, canonname, sa = res 
    # The AF_* and SOCK_* constants are now AddressFamily and SocketKind IntEnum collections. 
    try: 
     s = socket.socket(af, socktype, proto) 
    except OSError as msg: 
     s = None 
     continue 
    try: 
     s.bind(sa) 
     s.listen(1) 
    except OSError as msg: 
     s.close() 
     s = None 
     continue 
    break 
if s is None: 
    print('could not open socket') 
    sys.exit(1) 
conn, addr = s.accept() 
print('Connected by', addr) 
while True: 
    data = conn.recv(1024) 
    print(data) 
    if not data: break 
    conn.send(data) 
conn.close() 

當我運行這個程序時,我收到這個錯誤:[Errno 101]網絡無法訪問。而且,我無法ping通虛擬IPV6。

回答

0

2002:開頭的IPv6地址是6to4地址。有關如何使用和路由的特殊規則。您使用的地址與IPv4地址0.1.0.1相關聯,該地址不是有效的IPv4地址,因此您的IPv6地址也無效。

使用IPv6時,應使用ISP的官方地址。如果您無法從您的ISP獲取地址,並希望僅爲本地使用地址,請使用ULA地址。你可以自己生成。有多個網站可以使用在線生成器。