-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
646 additions
and
637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text; | ||
using NewLife; | ||
using NewLife.Data; | ||
using NewLife.Remoting; | ||
using NewLife.Security; | ||
|
||
namespace XApi | ||
namespace XApi; | ||
|
||
/// <summary>API控制器</summary> | ||
//[AllowAnonymous] | ||
public class MyApiController | ||
{ | ||
/// <summary>API控制器</summary> | ||
//[AllowAnonymous] | ||
public class MyApiController | ||
/// <summary>获取指定种类的环境信息</summary> | ||
/// <param name="kind"></param> | ||
/// <returns></returns> | ||
public String Info(String kind) | ||
{ | ||
/// <summary>获取指定种类的环境信息</summary> | ||
/// <param name="kind"></param> | ||
/// <returns></returns> | ||
public String Info(String kind) | ||
switch ((kind + "").ToLower()) | ||
{ | ||
switch ((kind + "").ToLower()) | ||
{ | ||
case "machine": return Environment.MachineName; | ||
case "user": return Environment.UserName; | ||
case "ip": return NetHelper.MyIP() + ""; | ||
case "time": return DateTime.Now.ToFullString(); | ||
default: | ||
throw new ApiException(505, "不支持类型" + kind); | ||
} | ||
case "machine": return Environment.MachineName; | ||
case "user": return Environment.UserName; | ||
case "ip": return NetHelper.MyIP() + ""; | ||
case "time": return DateTime.Now.ToFullString(); | ||
default: | ||
throw new ApiException(505, "不支持类型" + kind); | ||
} | ||
} | ||
|
||
/// <summary>加密数据</summary> | ||
/// <param name="data"></param> | ||
/// <returns></returns> | ||
public Packet Encrypt(Packet data) | ||
{ | ||
//Log.XTrace.WriteLine("加密数据{0:n0}字节", data.Total); | ||
/// <summary>加密数据</summary> | ||
/// <param name="data"></param> | ||
/// <returns></returns> | ||
public IPacket Encrypt(IPacket data) | ||
{ | ||
//Log.XTrace.WriteLine("加密数据{0:n0}字节", data.Total); | ||
|
||
var buf = data.ToArray().RC4("NewLife".GetBytes()); | ||
var buf = data.ReadBytes().RC4("NewLife".GetBytes()); | ||
|
||
return buf; | ||
} | ||
return (ArrayPacket)buf; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,52 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using NewLife.Data; | ||
|
||
namespace XCoder.XNet | ||
namespace XCoder.XNet; | ||
|
||
/// <summary>IP包</summary> | ||
public class IPPacket | ||
{ | ||
/// <summary>IP包</summary> | ||
public class IPPacket | ||
public Byte Version; | ||
public Byte Length; | ||
public Byte DiffServices; | ||
public UInt16 DataLength; | ||
public UInt16 Identification; | ||
public Byte Flag; | ||
public UInt16 Excursion; | ||
public Byte TTL; | ||
public ProtocolType Protocol; | ||
public UInt16 CheckSum; | ||
public IPAddress SrcAddr; | ||
public IPAddress DestAddr; | ||
public Byte[] Option; | ||
public IPacket Data; | ||
|
||
public IPPacket(IPacket pk) | ||
{ | ||
public Byte Version; | ||
public Byte Length; | ||
public Byte DiffServices; | ||
public UInt16 DataLength; | ||
public UInt16 Identification; | ||
public Byte Flag; | ||
public UInt16 Excursion; | ||
public Byte TTL; | ||
public ProtocolType Protocol; | ||
public UInt16 CheckSum; | ||
public IPAddress SrcAddr; | ||
public IPAddress DestAddr; | ||
public Byte[] Option; | ||
public Packet Data; | ||
|
||
public IPPacket(Packet pk) | ||
{ | ||
if (pk == null) throw new ArgumentNullException(nameof(pk)); | ||
|
||
var data = pk.ReadBytes(0, 20); | ||
|
||
Version = (Byte)((data[0] & 0xF0) >> 4); | ||
Length = (Byte)((data[0] & 0x0F) * 4); | ||
DiffServices = data[1]; | ||
DataLength = (UInt16)((data[2] << 8) + data[3]); | ||
Identification = (UInt16)((data[4] << 8) + data[5]); | ||
Flag = (Byte)(data[6] >> 5); | ||
Excursion = (UInt16)(((data[6] & 0x1F) << 8) + data[7]); | ||
TTL = data[8]; | ||
Protocol = (ProtocolType)data[9]; | ||
CheckSum = (UInt16)((data[10] << 8) + data[11]); | ||
|
||
SrcAddr = new IPAddress(pk.ReadBytes(12, 4)); | ||
DestAddr = new IPAddress(pk.ReadBytes(16, 4)); | ||
|
||
// 可选项 | ||
if (Length > 20) Option = pk.ReadBytes(20, Length - 20); | ||
|
||
Data = pk.Slice(Length, DataLength); | ||
} | ||
|
||
public override String ToString() => $"{SrcAddr} => {DestAddr} [{DataLength}]"; | ||
if (pk == null) throw new ArgumentNullException(nameof(pk)); | ||
|
||
var data = pk.ReadBytes(0, 20); | ||
|
||
Version = (Byte)((data[0] & 0xF0) >> 4); | ||
Length = (Byte)((data[0] & 0x0F) * 4); | ||
DiffServices = data[1]; | ||
DataLength = (UInt16)((data[2] << 8) + data[3]); | ||
Identification = (UInt16)((data[4] << 8) + data[5]); | ||
Flag = (Byte)(data[6] >> 5); | ||
Excursion = (UInt16)(((data[6] & 0x1F) << 8) + data[7]); | ||
TTL = data[8]; | ||
Protocol = (ProtocolType)data[9]; | ||
CheckSum = (UInt16)((data[10] << 8) + data[11]); | ||
|
||
SrcAddr = new IPAddress(pk.ReadBytes(12, 4)); | ||
DestAddr = new IPAddress(pk.ReadBytes(16, 4)); | ||
|
||
// 可选项 | ||
if (Length > 20) Option = pk.ReadBytes(20, Length - 20); | ||
|
||
Data = pk.Slice(Length, DataLength); | ||
} | ||
|
||
public override String ToString() => $"{SrcAddr} => {DestAddr} [{DataLength}]"; | ||
} |
Oops, something went wrong.