KingNET.PageLib/Helper/IpHelper.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Web;
using System.Net;
namespace KingNET.PageLib.Helper
{
/// <summary>
/// SERVER获取IP的帮助类
/// 获取客户端IP,服务器端IP
/// </summary>
public class IpHelper
{
/// <summary>
/// 从IP转换为Int32
/// </summary>
/// <param name="IpValue"></param>
/// <returns></returns>
public static UInt32 IPToUInt32(string IpValue)
{
string[] IpByte = IpValue.Split('.');
Int32 nUpperBound = IpByte.GetUpperBound(0);
if (nUpperBound != 3)
{
IpByte = new string[4];
for (Int32 i = 1; i <= 3 - nUpperBound; i++)
IpByte[nUpperBound + i] = "0";
}
byte[] TempByte4 = new byte[4];
for (Int32 i = 0; i <= 3; i++)
{
if (IsNumeric(IpByte[i]))
TempByte4[3 - i] = (byte)(Convert.ToInt32(IpByte[i]) & 0xff);
}
return BitConverter.ToUInt32(TempByte4, 0);
}
/// <summary>
/// 判断是否为数字
/// </summary>
/// <param name="str">待判断字符串</param>
/// <returns></returns>
protected static bool IsNumeric(string str)
{
if (str != null && System.Text.RegularExpressions.Regex.IsMatch(str, @"^-?\d+$"))
return true;
else
return false;
}
/// <summary>
/// 是否是测试环境IP
/// </summary>
后面还有 84 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。