Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipv6无法连接服务器 #211

Open
tanyue0504 opened this issue Aug 26, 2023 · 2 comments
Open

ipv6无法连接服务器 #211

tanyue0504 opened this issue Aug 26, 2023 · 2 comments

Comments

@tanyue0504
Copy link

版本1.12.2,java8,只安装了forge
连接ipv6服务器提示
io.netty.channel.AbstractChannel$AnnotatedSocketException: Protocol family unavailable:
请问是怎么回事,如何解决?
已经尝试了-Djava.net.preferIPv4Stack=false和-Djava.net.preferIPv6Address=true都无效

@scapking
Copy link

android 似乎无法使用 ipv6 联机。

你需要使用 termux 创建一个 流量转发

监听 25565 端口 加入游戏时候输入 127.0.0.1 25565

然后将 25565 端口流量 通过流量转发,抵达目标IPV6

也就是说你需要有IPV6和IPV4

@scapking
Copy link

import socket
import threading

def handle_client(client_socket, ipv6_host, ipv6_port):
ipv6_socket = None
try:
# 连接到IPv6地址
ipv6_socket = socket.create_connection((ipv6_host, ipv6_port))

    # 开启线程,将IPv4流量转发到IPv6
    threading.Thread(target=forward_traffic, args=(client_socket, ipv6_socket)).start()

    # 从IPv6接收数据并转发回IPv4
    data = ipv6_socket.recv(4096)
    while data:
        client_socket.sendall(data)
        data = ipv6_socket.recv(4096)

except Exception as e:
    print(f"[+] 错误信息: {e}")

finally:
    if ipv6_socket:
        ipv6_socket.close()
    client_socket.close()

def forward_traffic(src_socket, dest_socket):
try:
data = src_socket.recv(4096)
while data:
dest_socket.sendall(data)
data = src_socket.recv(4096)

except Exception as e:
    print(f"[+] 错误信息: {e}")

finally:
    src_socket.close()
    dest_socket.close()

def main():
# 设置IPv4监听地址和端口
ipv4_listen_address = "127.0.0.1"
ipv4_listen_port = 25565

# 设置IPv6目标地址和端口
ipv6_host = "scapking.top"  #这里修改成目标的域名
ipv6_port = 25565   #这里修改成目标端口

# 启动IPv4到IPv6的代理服务器
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as ipv4_socket:
    ipv4_socket.bind((ipv4_listen_address, ipv4_listen_port))
    ipv4_socket.listen(5)
    print(f"[+] 脚本成功启动,成功在 {ipv4_listen_address}:{ipv4_listen_port} 端口运行")

    while True:
        client, addr = ipv4_socket.accept()
        print(f"[+] IP: {addr[0]} 端口: {addr[1]}")
        threading.Thread(target=handle_client, args=(client, ipv6_host, ipv6_port)).start()

if name == "main":
main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants