本文介绍了Winsock的 - 为什么不是ZNC(和IRC保镖)接受我的Winsock连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用典型的IRC客户端,我可以输入:

  /服务器localhost 6667尼克:通

当我进入尼克:我通过配置为ZNC,(一个IRC保镖)我转发到ZNC下我的服务器/尼克连接到服务器:通过组合

我如何编程方式打开了所有的这些同步参数的Winsock连接? /服务器localhost 6667昵称:通过

我试过,但连接ZNC似乎被忽略了的请求后,发送数据。或者,我只是没有连接到它。这code已经连接不需要认证坪IRC服务器,所以我知道它的工作原理。

的#define AF_INET 2
#定义SOCK_STREAM 1
#定义SOL_SOCKET 0xFFFF的
#定义SO_SNDTIMEO 0x1005字符串SERVER_ADDR =127.0.0.1;
INT SERVER_PORT = 6667;无效ir​​cconnect(){
INT struct_sockaddr [4];
INT地址,port_low,port_high;
INT选择采用[1];
INT℃;如果(irc_disabled == 1)返回(0);//填写的sockaddr结构
地址= inet_addr(SERVER_ADDR);
port_low = SERVER_PORT&安培;设为0x00FF;
port_high =(SERVER_PORT&安培;为0xFF00)GT;> 8;
struct_sockaddr [0] = AF_INET | (port_high<< 16)| (port_low&所述;&下; 24);
struct_sockaddr [1] =地址;
struct_sockaddr [2] = 0;
struct_sockaddr [3] = 0;//连接
S =插座(AF_INET,SOCK_STREAM,0);OPTS [0] = 1000; //发送超时毫秒
setsockopt的(S,SOL_SOCKET,SO_SNDTIMEO,选择采用,4);
C =连接(S,struct_sockaddr,16);睡眠(5000);sendLine(缺口+:+密码);


解决方案

请参见下面的蟒蛇说明:

  INT struct_sockaddr [4];
INT地址,port_low,port_high;
INT选择采用[1];
INT℃;
串zncauth =缺口+:+密码;如果(irc_disabled == 1)返回(0);//填写的sockaddr结构
地址= inet_addr(SERVER_ADDR);
port_low = SERVER_PORT&安培;设为0x00FF;
port_high =(SERVER_PORT&安培;为0xFF00)GT;> 8;
struct_sockaddr [0] = AF_INET | (port_high<< 16)| (port_low&所述;&下; 24);
struct_sockaddr [1] =地址;
struct_sockaddr [2] = 0;
struct_sockaddr [3] = 0;//连接
S =插座(AF_INET,SOCK_STREAM,0);
OPTS [0] = 1000; //发送超时毫秒
setsockopt的(S,SOL_SOCKET,SO_SNDTIMEO,选择采用,4);
C =连接(S,struct_sockaddr,16);//发送
sendLine(尼克zncbotnick);
sendLine(用户ZNC BOT ZNC:ZNC);
sendLine(PASS+ zncauth);无效sendLine(字符串文本){
    如果(irc_disabled == 1)返回(0);
    文字文本= +\\ r \\ n;
    发送(S,文本,StringLen(文本),0);
}

在code以上的工程终于,这对我的作品在Python与ZNC进行身份验证。基本上,在其他语言,我被扔命令ZNC,但他们从来没有ZNC因为code失踪返回和换行符'\\ r \\ n'。与Python,我能诊断实时的问题。

 #!的/ usr /斌/包膜蟒蛇
# - * - 编码:UTF-8 - * - //Test.py
进口插座zncauth ='昵称:密码
SERVER_ADDR =127.0.0.1
SERVER_PORT = 6667
S = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((SERVER_ADDR,SERVER_PORT))
s.send('NICK botnick \\ r \\ n)
s.send('USER ZNC机器人ZNC:ZNC \\ r \\ n)
s.send('PASS'+ zncauth +\\ r \\ n)

Using a typical irc client I can type in:

/server localhost 6667 nick:pass

When I enter the nick:pass I configured for ZNC,(an IRC bouncer) I'm forwarded to the server that znc is connected to under my server/nick:pass combination.

How can I programmatically open a winsock connection with all of these arguments simultaneously? /server localhost 6667 nick:pass

I've tried sending the data after connecting but znc seems to be ignoring the requests. Or I'm just not connecting to it at all. This code has connected to an IRC server that doesn't require Ping authentication, so I know it works.

#define AF_INET                    2
#define SOCK_STREAM                1
#define SOL_SOCKET                 0xffff
#define SO_SNDTIMEO                0x1005

string server_addr = "127.0.0.1";
int server_port = 6667;

void ircconnect(){
int struct_sockaddr[4];
int addr, port_low, port_high;
int opts[1];
int c;

if (irc_disabled == 1) return(0);

// fill the sockaddr struct
addr = inet_addr(server_addr);
port_low = server_port & 0x00ff;
port_high = (server_port & 0xff00) >> 8; 
struct_sockaddr[0] = AF_INET | (port_high << 16) | (port_low << 24);
struct_sockaddr[1] = addr;
struct_sockaddr[2] = 0;
struct_sockaddr[3] = 0;

// connect
s = socket(AF_INET, SOCK_STREAM, 0);

opts[0] = 1000; // send timeout milliseconds
setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, opts, 4);
c = connect(s, struct_sockaddr, 16);

Sleep(5000);

sendLine(nick + ":" + password);
解决方案

See the python explanation below:

int struct_sockaddr[4];
int addr, port_low, port_high;
int opts[1];
int c;
string zncauth = nick + ":" + password;

if (irc_disabled == 1) return(0);

// fill the sockaddr struct
addr = inet_addr(server_addr);
port_low = server_port & 0x00ff;
port_high = (server_port & 0xff00) >> 8; 
struct_sockaddr[0] = AF_INET | (port_high << 16) | (port_low << 24);
struct_sockaddr[1] = addr;
struct_sockaddr[2] = 0;
struct_sockaddr[3] = 0;

// connect
s = socket(AF_INET, SOCK_STREAM, 0);
opts[0] = 1000; // send timeout milliseconds
setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, opts, 4);
c = connect(s, struct_sockaddr, 16);

// send
sendLine("NICK zncbotnick");
sendLine("USER znc bot znc :znc");
sendLine("PASS " + zncauth);

void sendLine(string text){
    if (irc_disabled == 1) return(0);
    text = text + "\r\n";
    send(s, text, StringLen(text), 0);
}

The code above finally works and this works for me in python to authenticate with ZNC. Basically, in the other language I was throwing commands to znc but they never got to znc because the code was missing return and newline characters '\r\n'. With python, I was able to diagnose the problem in real-time.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

//Test.py
import socket

zncauth = 'nick:password'
server_addr = '127.0.0.1'
server_port = 6667
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server_addr, server_port))   
s.send( 'NICK botnick\r\n')
s.send( 'USER znc bot znc :znc\r\n')
s.send( 'PASS ' + zncauth + ' \r\n')

这篇关于Winsock的 - 为什么不是ZNC(和IRC保镖)接受我的Winsock连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 15:19