IP 세그먼트에 따라 임의로 IP 생성
class CIP
{
private uint ip1;
private uint ip2;
public string ips = "";
public CIP(string ips)
{
this.ips = ips.Trim();
string[] ss = this.ips.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (ss.Length == 2)
{
ip1 = IPToInt(ss[0]);
ip2 = IPToInt(ss[1]);
}
}
public string IP1
{
get
{
return IntToIP(ip1);
}
}
public string IP2
{
get
{
return IntToIP(ip2);
}
}
public string RanIP
{
get
{
Random ra = new Random(unchecked((int)DateTime.Now.Ticks));
int len = (int)(ip2 - ip1);
uint ip = ip1 + (uint)ra.Next(len);
return IntToIP(ip);
}
}
///
/// IP uint
///
///
///
public static uint IPToInt(string strIP)
{
byte[] ip_bytes = new byte[4];
string[] strArr = strIP.Split(new char[] { '.' });
for (int i = 0; i < 4; i++)
{
ip_bytes[i] = byte.Parse(strArr[3 - i]);
}
return BitConverter.ToUInt32(ip_bytes, 0);
}
///
/// uint IP
///
///
///
public static string IntToIP(uint ip)
{
byte[] ip_bytes = BitConverter.GetBytes(ip);
string ip_str = "";
for (int i = 0; i < 4; i++)
{
ip_str += ((int)ip_bytes[3 - i]).ToString() + ".";
}
ip_str = ip_str.Remove(ip_str.Length - 1);
return ip_str;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
알고리즘 파트 3 : 스택을 사용하여 문자열 반전얘들 아. 오늘은 스택을 사용하여 문자열을 뒤집는 방법을 보여드리겠습니다. 이 문제에서 우리는 하나의 문자열을 받았고 스택을 사용하여 그것을 뒤집어야 합니다. 해결책 이것이 도움이 되길 바랍니다. 감사합니다 ❤....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.