class MK
{
Stream connection;
TcpClient con; public MK(string ip)
{
con = new TcpClient();
con.Connect(ip, );
connection = (Stream)con.GetStream();
}
public void Close()
{
connection.Close();
con.Close();
}
public bool Login(string username, string password)
{
Send("/login", true);
string hash = Read()[].Split(new string[] { "ret=" }, StringSplitOptions.None)[];
Send("/login");
Send("=name=" + username);
//在此先对已加密的密码进行解密操作(为确保数据安全,在保存密码的时候,对密码进行了公钥加密)
//password=.......;
Send("=response=00" + EncodePassword(password, hash), true);
if (Read()[] == "!done")
{
return true;
}
else
{
return false;
}
}
public void Send(string co, bool endsentence=false)
{
byte[] bajty = Encoding.UTF8.GetBytes(co.ToCharArray());
byte[] velikost = EncodeLength(bajty.Length); connection.Write(velikost, , velikost.Length);
connection.Write(bajty, , bajty.Length);
if(endsentence)
{
connection.WriteByte();
}
}
public List<string> Read()
{
List<string> output = new List<string>();
string o = "";
byte[] tmp = new byte[];
long count;
while (true)
{
tmp[] = (byte)connection.ReadByte();
//if(tmp[3] == 220) tmp[3] = (byte)connection.ReadByte(); it sometimes happend to me that
//mikrotik send 220 as some kind of "bonus" between words, this fixed things, not sure about it though
if (tmp[] == )
{
output.Add(o);
if (o.Substring(, ) == "!done")
{
break;
}
else
{
o = "";
continue;
}
}
else
{
if (tmp[] < 0x80)
{
count = tmp[];
}
else
{
if (tmp[] < 0xC0)
{
int tmpi = BitConverter.ToInt32(new byte[] { (byte)connection.ReadByte(), tmp[], , }, );
count = tmpi ^ 0x8000;
}
else
{
if (tmp[] < 0xE0)
{
tmp[] = (byte)connection.ReadByte();
int tmpi = BitConverter.ToInt32(new byte[] { (byte)connection.ReadByte(), tmp[], tmp[], }, );
count = tmpi ^ 0xC00000;
}
else
{
if (tmp[] < 0xF0)
{
tmp[] = (byte)connection.ReadByte();
tmp[] = (byte)connection.ReadByte();
int tmpi = BitConverter.ToInt32(new byte[] { (byte)connection.ReadByte(), tmp[], tmp[], tmp[] }, );
count = tmpi ^ 0xE0000000;
}
else
{
if (tmp[] == 0xF0)
{
tmp[] = (byte)connection.ReadByte();
tmp[] = (byte)connection.ReadByte();
tmp[] = (byte)connection.ReadByte();
tmp[] = (byte)connection.ReadByte();
count = BitConverter.ToInt32(tmp, );
}
else
{
//Error in packet reception, unknown length
break;
}
}
}
}
}
} for (int i = ; i < count; i++)
{
o += (Char)connection.ReadByte();
}
}
return output;
}
byte[] EncodeLength(int delka)
{
if (delka < 0x80)
{
byte[] tmp = BitConverter.GetBytes(delka);
return new byte[] { tmp[] };
}
if (delka < 0x4000)
{
byte[] tmp = BitConverter.GetBytes(delka | 0x8000);
return new byte[] { tmp[], tmp[] };
}
if (delka < 0x200000)
{
byte[] tmp = BitConverter.GetBytes(delka | 0xC00000);
return new byte[] { tmp[], tmp[], tmp[] };
}
if (delka < 0x10000000)
{
byte[] tmp = BitConverter.GetBytes(delka | 0xE0000000);
return new byte[] { tmp[], tmp[], tmp[], tmp[] };
}
else
{
byte[] tmp = BitConverter.GetBytes(delka);
return new byte[] { 0xF0, tmp[], tmp[], tmp[], tmp[] };
}
} public string EncodePassword(string Password, string hash)
{
byte[] hash_byte = new byte[hash.Length / ];
for (int i = ; i <= hash.Length - ; i += )
{
hash_byte[i / ] = Byte.Parse(hash.Substring(i, ), System.Globalization.NumberStyles.HexNumber);
}
byte[] heslo = new byte[ + Password.Length + hash_byte.Length];
heslo[] = ;
Encoding.UTF8.GetBytes(Password.ToCharArray()).CopyTo(heslo, );
hash_byte.CopyTo(heslo, + Password.Length); Byte[] hotovo;
System.Security.Cryptography.MD5 md5; md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); hotovo = md5.ComputeHash(heslo); //Convert encoded bytes back to a 'readable' string
string navrat = "";
foreach (byte h in hotovo)
{
navrat += h.ToString("x2");
}
return navrat;
}
}

c# ros的更多相关文章

  1. 阿里云VPS服务器,ROS内网穿透

    Aliyun Windows Server 2008 R2中建立vpn服务器,ros中使用pptp拨号连接 2.在Aliyun服务器中,修改hosts,将内网分配的ip映射到指定的域名,在Aliyun ...

  2. QT下调试基于ros的catkin项目

    1.首先告诉qt ros的搜索路径,通过修改qt creator 桌面启动程序来实现 sudo    gedit ~/.local/share/applications/DigiaQtOpenSour ...

  3. ROS学习(三)—— ROS文件系统

    一.预备工作 使用ros0tutorials程序包,先下载: sudo apt-get install ros-<distro>-ros-tutorials 其中<distro> ...

  4. ROS学习(二)—— 配置ROS环境

    一.管理环境 p { margin-bottom: 0.25cm; line-height: 120% } a:link { } 如果你在查找和使用ROS软件包方面遇到了问题,请确保你已经正确配置了脚 ...

  5. ROS学习(一)—— 环境搭建

    一.配置Ubuntu软件仓库且选择ROS正确版本 二.添加source.list sudo sh -c 'echo "deb http://packages.ros.org/ros/ubun ...

  6. [ROS] Studying Guidance

    Reference: https://www.zhihu.com/question/35788789 安装指南:http://wiki.ros.org/indigo/Installation/Ubun ...

  7. ros::spin() 和 ros::spinOnce() 区别及详解

    版权声明:本文为博主原创文章,转载请标明出处: http://www.cnblogs.com/liu-fa/p/5925381.html 博主提示:本文基于ROS Kinetic Kame,如有更(g ...

  8. Learning Roadmap of Robotic Operating System (ROS)

    ROS Wiki: http://wiki.ros.org/ Robots Using ROS Textbooks: A Gentle Introduction to ROS Learning ROS ...

  9. k-develop 在ros上面的应用

    sudo apt-get install kdevelop 根据wiki上面的ros 章节中,关于kdevelop的介绍,配置好环境即可. 导入工程时,选中src/src下面的章节,不过,需要注意去掉 ...

  10. ROS系统C++代码测试之gtest

    1. 安装gtestsudo apt-get install libgtest-dev 2.修改CMakeLists.txtfind_package(GTest REQUIRED)uncommend ...

随机推荐

  1. C#限速下载网络文件

    代码: using System; using System.Collections.Concurrent; using System.Collections.Generic; using Syste ...

  2. 【Asp.Net Core】二、添加控制器和视图

    控制器Controller 在添加控制器前,我们先看下它为我们自动生成的一些Controller,我们看下AccountController.cs 来看下登录验证方法Login async这个应该是异 ...

  3. C# - 多线程 之 进程与线程

    并行~并发 并发 Concurrency,逻辑上的同时发生,一个处理器(在不同时刻或者说在同一时间间隔内)"同时"处理多个任务.宏观上是并发的,微观上是按排队等待.唤醒.执行的步骤 ...

  4. 理解Java对象的交互:时钟显示程序

    实现: 结构: 对象:时钟  - 对象:小时                 - 对象:分钟 小时和分钟具有相同属性(值,上限),可以用一个类Display来定义这两个对象: 但是两者之间又具有联系( ...

  5. 使用 Vue 2.0 实现服务端渲染的 HackerNews

    Vue 2.0 支持服务端渲染 (SSR),并且是流式的,可以做组件级的缓存,这使得极速渲染成为可能.同时, 和 2.0 也都能够配合 SSR 提供同构路由和客户端 state hydration.v ...

  6. 应用Apache Axis进行Web Service开发

    转自(http://tscjsj.blog.51cto.com/412451/84813) 一.概述 SOAP原意为Simple Object Access Protocol(简单对象访问协议),是一 ...

  7. 非域客户端的office使用RMS加密服务出现‘介绍“信息权限管理服务”’服务的提示

    环境:office2007,需要使用windows RMS服务,客户机处于工作组模式,如图: 出现这个说明客户机没有发现RMS服务,可以通过导入注册表解决,如下: Windows Registry E ...

  8. 360安全卫士造成Sharepoint文档库”使用资源管理器打开“异常

           备注:企业用户还是少用360为妙        有客户反馈:部门里的XP SP2环境客户机全部异常,使用资源管理器打开Sharepoint文档库,看到的界面样式很老土,跟本地文件夹不一样 ...

  9. 自定义UITabBarController标签视图控制器

    首先创建一个类,继承自UItabBarController 然后在.m文件中: 这里我有两个宏定义: #define WIDTH (myView.frame.size.width / 4) //我在写 ...

  10. 苹果 OS X 系统U盘重装-抹盘重装、系统盘制作

    鉴于前段时间系统出了点问题,然后直接将盘抹了,来个彻底干净的系统重装.这里敲下过程.(网络恢复太慢了,我整整一个晚上竟然没down下来,恼怒了,直接U盘装) First,系统盘制作: 1.首先需要有: ...