Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
自动获取IP方案1
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoLogueChi committed Feb 25, 2018
1 parent 72fa0f4 commit 43d022b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Drcom/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Button Content="登陆" HorizontalAlignment="Left" Margin="245,266,0,0" VerticalAlignment="Top" Width="75" Click="LoginNet"/>
<Label Content="登陆ip" HorizontalAlignment="Left" Margin="23,95,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="TextIp" HorizontalAlignment="Left" Height="23" Margin="73,99,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="135"/>
<CheckBox x:Name="SaveIp" Content="记住IP" HorizontalAlignment="Left" Margin="287,101,0,0" VerticalAlignment="Top"/>
<CheckBox x:Name="GetIp" Content="自动获取IP" HorizontalAlignment="Left" Margin="287,101,0,0" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="300,305,0,0" TextWrapping="Wrap" Text="关于软件" VerticalAlignment="Top" Foreground="Blue" TextDecorations="Underline" MouseDown="About"/>
<TextBlock HorizontalAlignment="Left" Margin="220,305,0,0" TextWrapping="Wrap" Text="检查更新" VerticalAlignment="Top" Foreground="Blue" TextDecorations="Underline" MouseDown="FindNew"/>

Expand Down
21 changes: 16 additions & 5 deletions Drcom/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
if (Setting.GetSetting("nip") != "")
if (Setting.GetSetting("nip") == "")
{
GetIp.IsChecked = true;
}
else
{
SaveIp.IsChecked = true;
TextIp.Text = Setting.GetSetting("nip");
}
if (Setting.GetSetting("uid") != "")
Expand All @@ -38,11 +41,13 @@ private void LoginNet(object sender, RoutedEventArgs e)
string uid = TextUid.Text;
string pwd = TextPwd.Password;

//保存ip账号密码
if (SaveIp.IsChecked == true)
//获取登陆IP
if (GetIp.IsChecked == true)
{
Setting.UpdateSetting("nip", nip);
TextIp.Text = CsuNet.LoginIP();
}
//保存IP,账号和密码
Setting.UpdateSetting("nip", nip);
if (SaveUid.IsChecked == true)
{
Setting.UpdateSetting("uid", uid);
Expand All @@ -60,6 +65,12 @@ private void LoginNet(object sender, RoutedEventArgs e)
//注销按钮
private void LogoutNet(object sender, RoutedEventArgs e)
{
//获取登陆IP
if (GetIp.IsChecked == true)
{
TextIp.Text = CsuNet.LoginIP();
}

string nip = TextIp.Text;

var relust = CsuNet.LogoutCsuNet(nip);
Expand Down
4 changes: 2 additions & 2 deletions Drcom/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.1.0")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
34 changes: 33 additions & 1 deletion Drcom/net/CsuNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@ namespace Drcom.net
{
public class CsuNet
{
//获取登陆IP
public static string LoginIP()
{
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.qq.com/");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.ASCII))
{
string result = reader.ReadToEnd();

if (result.Contains("v4serip"))
{
string[] Fnip = Regex.Split(result, "v4serip='", RegexOptions.IgnoreCase);
string[] nip = Regex.Split(Fnip[1], "'", RegexOptions.IgnoreCase);
return nip[0];
}
else
{
return null;
}
}
}
catch (Exception e)
{
return null;
}
}


//登陆
public static string LoginCsuNet(string nip, string uid, string pwd)
{
Expand Down Expand Up @@ -62,7 +94,7 @@ public static string LogoutCsuNet(string nip)
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.ASCII))
{
var result = reader.ReadToEnd();
string result = reader.ReadToEnd();
return LoginCaes(result);
}
}
Expand Down

0 comments on commit 43d022b

Please sign in to comment.