C# - 插槽登录到防火墙 [英] C# - Socket to log on to Firewall

查看:176
本文介绍了C# - 插槽登录到防火墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个应用程序来自动连接到我们不同的防火墙。所有这些具有相同的前端工作。我们telnet到IP,他们给的消息登录或注销,并要求输入用户名和密码。

I wrote an app to automatically connect to our different Firewalls. All of them work with the same frontend. We telnet to the IP and they give the message LOGIN or LOGOUT and ask for a username or password.

我用这个code:

    public static void ConnectToFirewall(string strUsername, string strPassword, string strFirewallIp)
    {
        IPAddress[] ipaIpAddressCollection = Dns.GetHostAddresses(strFirewallIp);
        IPEndPoint ipeIpEndPoint = new IPEndPoint(ipaIpAddressCollection[0], intPort);
        Socket sckSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        sckSocket.Connect(ipeIpEndPoint);
        string strData = strUsername + "\r\n"+ strPassword + "\r\n";
        byte[] bytData = new byte[1024];
        bytData = Encoding.ASCII.GetBytes(strData);
        sckSocket.Send(bytData);
        byte[] bytDataReceived = new byte[1024];
        int intData = sckSocket.Receive(bytDataReceived);
        sckSocket.Close();
    }

如果我没有登录,当我telnet到它,我收到消息:登录,用户名:/密码:。 如果我登录,我收到注销,用户名:/密码

If I am not logged in, when I telnet to it, I receive the message: LOGIN, username: / Password:. If I am logged on, I receive LOGOUT, username: / Password.

这工作得很好与我一半的防火墙上面的方法,它似乎并没有工作(我不断收到登录,如果我没有试图通过凭证)。 我也试图与

This works perfectly well with the above method for half of my firewalls, it does not seem to work (I keep getting login as if I had not tried to pass credentials). I also tried it with

    TcpClient tcpConnection = new TcpClient(myip,myport);

但是这给了相同的结果。它适用于某些防火墙IP的。失败的人。它们都在同一域中。

but this gives the same result. It works for certain firewall ip's. fails for others. They are all in the same domain.

有没有人有想法如何,我可以过去,这还是什么措施,我可以承担解决此还是什么可能有些服务器不接受这种方法的原因,allthough它不接受,如果我telnet到它?

Does anyone have idea how I could get past this or what steps I could undertake to troubleshoot this or what may be the cause of some server not accepting this method, allthough it does accept if I telnet to it?

任何帮助或建议AP preciated。

Any help or suggestions are appreciated.

在预先感谢。

推荐答案

当你调用 sckSocket.Send(bytData),如何套接字知道只发送部分的 bytData 已初始化的用户名和密码?我有一种感觉,发送()将发送整个 1024 字节沿,其中大部分将是 0×00 字节。我不希望一个路由器来处理优雅。

When you call sckSocket.Send(bytData), how does the socket know to send only the portion of the bytData that has been initialized with the username and password? I have a feeling that Send() will send the entire 1024 bytes along, most of which will be 0x00 bytes. I would not expect a router to handle this gracefully.

我已经看到了,接受了密码才能的的提示输入密码已生成和发送系统。尝试使用两个单独的请求发送用户名和密码。如果你的环境使其成为可行的设置 TCP_NODELAY 套接字选项来禁用的 Nagle算法,它可能有助于获得更快速地沿着发送的用户名字符串。 (我不会用这个麻烦,除非你的的拆分分开发送的密码的用户名。)

I've seen systems that accepted the password only after the prompt for the password has been generated and sent. Try sending the username and password with two separate requests. If your environment makes it feasible to set the TCP_NODELAY socket option to disable Nagle's algorithm, it might help to get the username string sent along more quickly. (I wouldn't bother with this unless you also split apart sending the username from the password.)

这篇关于C# - 插槽登录到防火墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆