嘿evryone我正在尝试创建一个IP地址比较,所以当用户登录时他/她需要进行测试,以查看mysql数据库上的IP是否是系统计算机上的IP
我一直没有将错误对象引用设置为对象,因为我不知道如何从C#获取用户IP我尝试了很多代码但似乎无法将它们转换为int32s
这是我的代码
private void CheckIf1Login()
{
MySqlConnection conn = new MySqlConnection(myConnection);
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT ip_addr FROM `as_users` WHERE username = '" + Form1.TextBoxText + "'";
conn.Open();
MySqlCommand SelectCommand = new MySqlCommand("SELECT ip_addr'", conn);
int IP2 = Convert.ToInt32(cmd.ExecuteScalar());
string ipAddress = HttpContext.Current.Request.UserHostAddress;
uint IP3 = GetIpAsUInt32(ipAddress);
MessageBox.Show("" + IP3);
if (IP2 == IP3)
{
MessageBox.Show("Whoops! It seems that your package subscribtion has expired, to renew it please click here.");
}
else
{
CheckPackageType();
}
}
public uint GetIpAsUInt32(string ipString)
{
IPAddress address = IPAddress.Parse(ipString);
byte[] ipBytes = address.GetAddressBytes();
Array.Reverse(ipBytes);
return BitConverter.ToUInt32(ipBytes, 0);
}