资源简介
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)
{
相关资源
- FtpClient 组件和源码(c#)
- winform(c#)最全73种非常漂亮界面样式
- 桌面应用界面(C#)
- 周立功CAN通用上位机例程(C#)
- 试题库管理系统毕业论文(C#)源程序
- 有史以来最简单的三层(C#)
- 杭州三汇语音卡电话拨号程序源代码
- ASP.NET(c#) 从零动态生成Word文件用程
- .NET(c#)Web生成二维码
- 基于Web的实验室管理系统(C#)
- 课程表-日程表(C#)
- ArcGIS-Engine基础开发教程(C#)C#二次开
- ASP.NET(C#)物业管理系统完整代码
- asp.net(c#)校园新闻管理系统源码
- asp.net(C#)房屋中介管理系统
- ASP.net 网上商城完整源码(C#)
- 基于C/S架构的学生选课系统(C#)
- Google Authenticator in ASP.NET (C#)
- 宾馆管理信息系统(c#)数据库
- ASP.NET(C#)开发网上书店管理系统
- asp.net留言板源代码(C#)
- 数据结构与算法(C#)
- 药店管理系统 B/S模式 asp.net(C#)+
- 上位机(C#)MX Component以太网连接三菱
- 设备管理系统(C#)
- asp.net(c#)客户关系管理系统CRM
- asp.net(c#)开源权限管理系统
- winform(c#)集成所有opencv功能demo
- 小波阈值降噪算法(C#)
- vs2008asp.net(c#)某汽车销售公司网站
评论
共有 条评论