本文整理汇总了C#中System.Net.IPAddress.LastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# IPAddress.LastIndexOf方法的具体用法?C# IPAddress.LastIndexOf怎么用?C# IPAddress.LastIndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.IPAddress
的用法示例。
在下文中一共展示了IPAddress.LastIndexOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryCalculateIp
protected static IPAddress TryCalculateIp(string aIp)
{
try
{
// this works not in mono?!
return IPAddress.Parse(aIp);
}
catch (FormatException)
{
#region WTF - FLIP THE IP BECAUSE ITS REVERSED?!
string ip = new IPAddress(long.Parse(aIp)).ToString();
string realIp = "";
int pos = ip.LastIndexOf('.');
realIp += ip.Substring(pos + 1) + ".";
ip = ip.Substring(0, pos);
pos = ip.LastIndexOf('.');
realIp += ip.Substring(pos + 1) + ".";
ip = ip.Substring(0, pos);
pos = ip.LastIndexOf('.');
realIp += ip.Substring(pos + 1) + ".";
ip = ip.Substring(0, pos);
pos = ip.LastIndexOf('.');
realIp += ip.Substring(pos + 1);
return IPAddress.Parse(realIp);
#endregion
}
}
示例2: Parse
protected override void Parse(Core.Server aServer, string aRawData, string aMessage, string[] aCommands)
{
ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType + "(" + aServer.Name + ")");
string tUserName = aCommands[0].Split('!')[0];
Channel tChan = aServer.Channel(aCommands[2]);
Bot tBot = aServer.Bot(tUserName);
#region VERSION
if (aMessage == "VERSION")
{
log.Info("Parse() VERSION: " + Settings.Instance.IrcVersion);
FireSendData(aServer, "NOTICE " + tUserName + " :\u0001VERSION " + Settings.Instance.IrcVersion + "\u0001");
return;
}
#endregion
#region XGVERSION
if (aMessage == "XGVERSION")
{
log.Info("Parse() XGVERSION: " + Settings.Instance.XgVersion);
FireSendData(aServer, "NOTICE " + tUserName + " :\u0001XGVERSION " + Settings.Instance.XgVersion + "\u0001");
return;
}
#endregion
#region DCC DOWNLOAD MESSAGE
if (aMessage.StartsWith("DCC") && tBot != null)
{
Packet tPacket = tBot.OldestActivePacket();
if (tPacket != null)
{
if (tPacket.Connected)
{
log.Error("Parse() ignoring dcc from " + tBot + " because " + tPacket + " is already connected");
}
else
{
bool isOk = false;
int tPort = 0;
Int64 tChunk = 0;
string[] tDataList = aMessage.Split(' ');
if (tDataList[1] == "SEND")
{
log.Info("Parse() DCC from " + tBot);
// if the name of the file contains spaces, we have to replace em
if (aMessage.StartsWith("DCC SEND \""))
{
Match tMatch = Regex.Match(aMessage, "DCC SEND \"(?<packet_name>.+)\"(?<bot_data>[^\"]+)$");
if (tMatch.Success)
{
aMessage = "DCC SEND " + tMatch.Groups["packet_name"].ToString().Replace(" ", "_").Replace("'", "") + tMatch.Groups["bot_data"];
tDataList = aMessage.Split(' ');
}
}
#region IP CALCULATING
try
{
// this works not in mono?!
tBot.Ip = IPAddress.Parse(tDataList[3]);
}
catch (FormatException)
{
#region WTF - FLIP THE IP BECAUSE ITS REVERSED?!
string ip;
try
{
ip = new IPAddress(long.Parse(tDataList[3])).ToString();
}
catch (Exception ex)
{
log.Fatal("Parse() " + tBot + " - can not parse bot ip from string: " + aMessage, ex);
return;
}
string realIp = "";
int pos = ip.LastIndexOf('.');
try
{
realIp += ip.Substring(pos + 1) + ".";
ip = ip.Substring(0, pos);
pos = ip.LastIndexOf('.');
realIp += ip.Substring(pos + 1) + ".";
ip = ip.Substring(0, pos);
pos = ip.LastIndexOf('.');
realIp += ip.Substring(pos + 1) + ".";
ip = ip.Substring(0, pos);
pos = ip.LastIndexOf('.');
realIp += ip.Substring(pos + 1);
//.........这里部分代码省略.........