资源简介
C# 语言的ROS API,可以实现登录、获取winbox中的信息
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net.Sockets;
namespace WindowsFormsApplication
{
///
/// ROS API(C#)
///
public class MK
{
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)
{
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)
{
byte[] bajty = Encoding.ASCII.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.ASCII.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();
//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);
if (o.Substring(0 5) == “!done“)
{
break;
}
else
{
o = ““;
continue;
}
}
else
{
if (tmp[3] < 0x80)
{
count = tmp[3];
}
else
{
if (tmp[3] < 0xC0)
{
相关资源
- Rs232串口调试信息传输(C#)
- 单纯形法源程序(C#)
- 猜数字游戏 (C#)
- .net(C#)用户登陆自定义控件
- 实现自定义的Web服务器(C#)
- (C#)局域网二人军棋对战游戏
- 显示所有缓存 清除所有缓存 Asp.net(
- asp.net(C#)开发的大型OA系统开源
- 简单IM系统源码(C#)
- 开源无线热点发现工具Inssider源代码(
- 杨中科老师的全13季 .NET视频教程(
- QRCode二维码编码支持中文生成二维码
- HIS医院管理系统源码(c#)
- winform(c#)最全60种非常漂亮界面样式
- mongodb gridfs .NET(C#) 文件存储
- 微信小程序带后端(C#)
- websocketService服务端(c#)
- 循环赛日程表(C#)
- 数据库课程设计员工管理系统(C#)
- 八数码问题(C#)
- 四则运算表达式解析器源码(C#)
- TestClose 用VisualStudio2005(C#)实现的进
- ribbon winform开源ribbon控件(c#)
- MakeTwoBarCode(CSharp) 2012年最新二维码
- asp.net 2.0管理系统开发(C#)经典案例
- 网上自动答疑系统(C#)
- asp.net(c#)批量打印功能实现
- usbCan(c#)
- 支付宝 网页授权 获取用户信息Demo(
- LL(1)文法判定(C#)
评论
共有 条评论