bind
IS-IT--Management
- Dec 13, 2004
- 25
Hello Experts,
I'm desperately seeking assistance with this issue I'm having.
I'm getting the following error:
Cannot access a non-static member of outer type 'BindsTools.PortScanner' via nested type 'BindsTools.PortScanner.PortScannerr'
I've been banging my head against a wall, I've looked up outer and inner types examples but just can't seem to get this working properly.
Can anyone assist me with this?
Thank you much!
And the code for the C#.net form is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace BindsTools
{
public partial class PortScanner : Form
{
public PortScanner()
{
InitializeComponent();
}
public void AddHeaderInformation(string name, string value)
{
ListViewItem lvi = this.listView1.Items.Add(name);
lvi.SubItems.Add(value);
}
private void button1_Click(object sender, EventArgs e)
{
string host;
int portStart = 1, portStop = 65535, ctrThread = 200;
host = textBox1.Text;
portStart = int.Parse(textBox2.Text);
portStop = int.Parse(textBox3.Text);
ctrThread = int.Parse(textBox4.Text);
PortScannerr ps = new PortScannerr(host, portStart, portStop);
ps.start(ctrThread);
}
public class PortScannerr
{
private string host;
private PortList portList;
public PortScannerr(string host, int portStart, int portStop)
{
this.host = host;
this.portList = new PortList(portStart, portStop);
}
public PortScannerr(string host)
: this(host, 1, 65535)
{
}
public PortScannerr()
: this("127.0.0.1")
{
}
public void start(int threadCtr)
{
for (int i = 0; i < threadCtr; i++)
{
Thread th = new Thread(new ThreadStart(run));
th.Start();
}
}
public void run()
{
int port;
TcpClient tcp = new TcpClient();
while ((port = portList.getNext()) != -1)
{
try
{
tcp = new TcpClient(host, port);
}
catch
{
continue;
}
finally
{
try
{
tcp.Close();
}
catch { }
}
//PortScanner oc = new PortScanner;
//MessageBox.Show(port.ToString() + " is open");
AddHeaderInformation(port.ToString(), "open");
}
}
}
public class PortList
{
private int start;
private int stop;
private int ptr;
public PortList(int start, int stop)
{
this.start = start;
this.stop = stop;
this.ptr = start;
}
public PortList()
: this(1, 65535)
{
}
public bool hasMore()
{
return (stop - ptr) >= 0;
}
public int getNext()
{
if (hasMore())
return ptr++;
return -1;
}
}
}
}
I'm desperately seeking assistance with this issue I'm having.
I'm getting the following error:
Cannot access a non-static member of outer type 'BindsTools.PortScanner' via nested type 'BindsTools.PortScanner.PortScannerr'
I've been banging my head against a wall, I've looked up outer and inner types examples but just can't seem to get this working properly.
Can anyone assist me with this?
Thank you much!
And the code for the C#.net form is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace BindsTools
{
public partial class PortScanner : Form
{
public PortScanner()
{
InitializeComponent();
}
public void AddHeaderInformation(string name, string value)
{
ListViewItem lvi = this.listView1.Items.Add(name);
lvi.SubItems.Add(value);
}
private void button1_Click(object sender, EventArgs e)
{
string host;
int portStart = 1, portStop = 65535, ctrThread = 200;
host = textBox1.Text;
portStart = int.Parse(textBox2.Text);
portStop = int.Parse(textBox3.Text);
ctrThread = int.Parse(textBox4.Text);
PortScannerr ps = new PortScannerr(host, portStart, portStop);
ps.start(ctrThread);
}
public class PortScannerr
{
private string host;
private PortList portList;
public PortScannerr(string host, int portStart, int portStop)
{
this.host = host;
this.portList = new PortList(portStart, portStop);
}
public PortScannerr(string host)
: this(host, 1, 65535)
{
}
public PortScannerr()
: this("127.0.0.1")
{
}
public void start(int threadCtr)
{
for (int i = 0; i < threadCtr; i++)
{
Thread th = new Thread(new ThreadStart(run));
th.Start();
}
}
public void run()
{
int port;
TcpClient tcp = new TcpClient();
while ((port = portList.getNext()) != -1)
{
try
{
tcp = new TcpClient(host, port);
}
catch
{
continue;
}
finally
{
try
{
tcp.Close();
}
catch { }
}
//PortScanner oc = new PortScanner;
//MessageBox.Show(port.ToString() + " is open");
AddHeaderInformation(port.ToString(), "open");
}
}
}
public class PortList
{
private int start;
private int stop;
private int ptr;
public PortList(int start, int stop)
{
this.start = start;
this.stop = stop;
this.ptr = start;
}
public PortList()
: this(1, 65535)
{
}
public bool hasMore()
{
return (stop - ptr) >= 0;
}
public int getNext()
{
if (hasMore())
return ptr++;
return -1;
}
}
}
}