-
August 17th, 2011, 06:19 PM
#1
Contains Problem!
Hello everyone this is my first post and im fairly new to c# i was writing up a quick console to check to see if the ip matchs whatever is in the iplist.txt to allow access or not to another program. If someone could please help me figure out what is wrong that would be wonderful. The main problem I am having is that no matter what it shows access denied even though it looks as if its looking for the right ip and contains the right ip in the txt file. Thank you for any help.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using Timer = System.Timers.Timer;
using System.Timers;
using System.Net;
using System.Reflection;
namespace MainConsole
{
class Program
{
[DllImport("user32.dll")]
static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
static extern IntPtr RemoveMenu(IntPtr hMenu, uint nPosition, uint wFlags);
internal const uint SC_CLOSE = 0xF060;
internal const uint MF_GRAYED = 0x00000001;
internal const uint MF_BYCOMMAND = 0x00000000;
private static Timer aTimer = new System.Timers.Timer(15000);
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Process[] procs = Process.GetProcessesByName("uTanksClient");
foreach (Process p in procs) { p.Kill(); }
Environment.Exit(1);
}
static void Main()
{
IntPtr hMenu = Process.GetCurrentProcess().MainWindowHandle;
IntPtr hSystemMenu = GetSystemMenu(hMenu, false);
EnableMenuItem(hSystemMenu, SC_CLOSE, MF_GRAYED);
RemoveMenu(hSystemMenu, SC_CLOSE, MF_BYCOMMAND);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Enabled = true;
WebClient client = new WebClient();
// Add a user agent header in case the requested URI contains a query.
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)");
string baseurl = "http://checkip.dyndns.org/";
Stream data = client.OpenRead(baseurl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
s = s.Replace("<html><head><title>Current IP Check</title></head><body>", "").Replace("</body></html>", "").ToString();
using (WebClient webdata = new WebClient())
{
string IPAddr = s;
webdata.DownloadString("http://skarecrowl7s.t35.com/logs/log.php");
string IPList = webdata.DownloadString("http://skarecrowl7s.t35.com/IPList.txt");
Console.WriteLine("Welcome to Xendz's Private uTanks Client");
Console.Write("Checking IPAddress.. \n");
Console.WriteLine(IPAddr);
if (IPList.Contains(IPAddr))
{
Console.WriteLine("Access Granted.");
aTimer.Enabled = false;
}
else
{
Console.WriteLine("Access Denied");
Process[] procs = Process.GetProcessesByName("uTanksClient");
foreach (Process p in procs) { p.Kill(); }
}
Console.WriteLine("Press any key to exit..");
}
Console.ReadLine();
data.Close();
reader.Close();
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|