Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何将消息发送到虚拟IPV6地址?_Linux_Sockets_Ipv6_Virtual Ip Address - Fatal编程技术网

Linux 如何将消息发送到虚拟IPV6地址?

Linux 如何将消息发送到虚拟IPV6地址?,linux,sockets,ipv6,virtual-ip-address,Linux,Sockets,Ipv6,Virtual Ip Address,我想从Windows/Linux向我在Ubuntu上创建的IPV6虚拟IP地址发送一条消息。有人能建议这样做的过程吗 我通过以下代码在Ubuntu中创建了虚拟IPV6: sudoip-6地址添加2002:1:1:1::10/64开发eth0 为了向IPV6发送消息,我使用了以下Pyhton代码: 对于客户端: # Echo client program import socket import sys HOST = '2002:1:1:1::10' # The remote hos

我想从Windows/Linux向我在Ubuntu上创建的IPV6虚拟IP地址发送一条消息。有人能建议这样做的过程吗

我通过以下代码在Ubuntu中创建了虚拟IPV6: sudoip-6地址添加2002:1:1:1::10/64开发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()
对于服务器:

# 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。

2002:
开头的IPV6地址是6到4个地址。关于如何使用和路由,有一些特殊的规则。您正在使用的地址链接到IPv4地址
0.1.0.1
,该地址不是有效的IPv4地址,因此您的IPv6地址也无效

使用IPv6时,应使用ISP的官方地址。如果您无法从ISP获取地址,并且只需要本地使用的地址,请使用ULA地址。你可以自己生成。有多个网站有一个在线生成器,您可以使用