first commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using DotNetty.Transport.Channels;
|
||||
using System.Net;
|
||||
|
||||
namespace JSMachine.WMS.Netty.Common.Util
|
||||
{
|
||||
public static class ChannelHandlerContextUtil
|
||||
{
|
||||
public static IPInfo ToIPInfo(this IChannelHandlerContext channel, AddressOnwer addressOnwer)
|
||||
{
|
||||
IPEndPoint iPAddress = addressOnwer == AddressOnwer.Local ? (IPEndPoint)channel.Channel.LocalAddress
|
||||
: (IPEndPoint)channel.Channel.RemoteAddress;
|
||||
string ip = iPAddress?.Address.MapToIPv4().ToString();
|
||||
int port = iPAddress == null ? 0 : iPAddress.Port;
|
||||
|
||||
return new IPInfo { IP = ip, Port = port };
|
||||
}
|
||||
}
|
||||
|
||||
public class IPInfo
|
||||
{
|
||||
public string IP { get; set; }
|
||||
public int Port { get; set; }
|
||||
}
|
||||
|
||||
public enum AddressOnwer
|
||||
{
|
||||
Local = 0,
|
||||
Remote = 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user