资源简介
MIKROTIK ROS API C#版,解决中文乱码,支持用户名,中文备注
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Sockets;
using System.Windows.Forms;
namespace ROSAPI
{
class MK //ROS API类
{
Stream connection;
TcpClient con;
public MK(string ip)//连接实例
{
con = new TcpClient();
con.Connect(ip 8728);
connection = (Stream)con.GetStream();
}
public void Close()//连接关闭
{
connection.Close();
con.Close();
}
public bool Login(string username string password)//登陆ROS
{
Send(“/login“ true);
string hash = Read()[0].Split(new string[] { “ret=“ } StringSplitOptions.None)[1];
Send(“/login“);
Send(“=name=“ + username);
Send(“=response=00“ + EncodePassword(password hash) true);
if (Read()[0] == “!done“)
{
return true;
}
else
{
return false;
}
}
public void Send(string co)//发送参数,发送修改命令,操作ROS
{
//byte[] bajty = Encoding.ASCII.GetBytes(co.ToCharArray());
byte[] bajty = Encoding.Default.GetBytes(co.ToCharArray());//转为中文编码
byte[] velikost = EncodeLength(bajty.Length);
connection.Write(velikost 0 velikost.Length);
connection.Write(bajty 0 bajty.Length);
}
public void Send(string co bool endsentence)//读取服务器数据
{
byte[] bajty = Encoding.Default.GetBytes(co.ToCharArray());//转为中文编码
byte[] velikost = EncodeLength(bajty.Length);
connection.Write(velikost 0 velikost.Length);
connection.Write(bajty 0 bajty.Length);
connection.WriteByte(0);
}
public List Read()//读取数据
{
List output = new List();
string o = ““;
byte[] tmp = new byte[4];
long count;
while (true)
{
tmp[3] = (byte)connection.ReadByte();//读取Stream返回的数据,就是ROS返回的数据
//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[3] == 0)//返回空
{
output.Add(o);//返回空,T类output则为加字符串o的值
if (o.Substring(0 5) == “!done“)
{
break;
}
else
{
o = ““;
continue;
}
}
else
{
if (tmp[3] < 0x80
相关资源
- 最新C#9.0官方中文教程(共1866页)
- 输入框自动切换中文(C#winform)vs20
- C# 植物大战僵尸中文版
- Net Core快速开发框架(支持Swagger API)
- Microsoft® Visual C#® 2010 Step by
- unity5圣典中文API手册v0.02.chm
- CSharp language specification 5.0中文(C# 语
- 百度在线翻译API (使用)
- C# 创建doc文档(基于Microsoft.Office.In
- 基于webapi的PLC软件控制(softplc)
- 调用百度地图API进行批量经纬度获取
- WinAPI 获取光标形状
- C# 调用win32 api函数-user32.dll详细说明
- Microsoft.ReportViewer的Dll合集 9.0
- Unity5实战:使用C#和Unity开发多平台游
- C#入门经典(第5版)中文高清版含代
-
Visual.Studio.NET.fr
amework技术内幕(高 - HelixToolkitWPF中文手册.rar
- C# 实现GPS交互
- C#测试驱动开发(中文清晰版)
- .NET C# 封装微信API操作类源码
- C#语言定义文档 中文版(微软官网)
- Effective C# 中文版
- ASP.NET微信开发包括图文上传菜单上传
- C#本质论(中文版)[超清晰]
- C#文档中文版(微软)
- C#网络抓包MySniffer+WinPcap_中文技术文档
- Asp.net Mvc开源论坛mvcforum中版源码
- ASP.NET MVC 5入门指南(中文PDF+源码)
- c# webapi 实现科大讯飞语音听写功能
评论
共有 条评论