private void btnlogin_Click(object sender, EventArgs e)
{
string dir = "D://Login.hhh";
if (!File.Exists(dir))
{
File.Create(dir);
}
string filePath = dir;
string s = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
string s1 = getIP();
using (StreamWriter swrObj = new StreamWriter(filePath, true))
{
swrObj.Write(s1 + "|" + s + "|" + Txtusername.Text + "|" + "user logged in on :|" + DateTime.Now.ToShortDateString() + " at " + DateTime.Now.ToShortTimeString());
swrObj.Write("\t\t");
swrObj.Write("\t\t");
swrObj.WriteLine();
MessageBox.Show("Login success");
}
}
private void Loginform_Load(object sender, EventArgs e)
{
}
private string getIP()
{
IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily.ToString() == "InterNetwork")
{
localIP = ip.ToString();
}
}
return localIP;
}
我正在使用上述代码获取单个用户的登录信息,但我想获取连接到服务器的多个用户的登录信息,并且该信息应保存在位于服务器中的目录中。谁能帮我。