Created
May 3, 2015 08:16
-
-
Save cmpunches/54877810b35663b3c24c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using System.Net.Sockets; | |
using System.Net; | |
namespace ProxyPunch | |
{ | |
public partial class frmMain : Form | |
{ | |
public string ProxyEndpoint | |
{ | |
get { return txtSocksIP.Text; } | |
} | |
public string ProxyPort | |
{ | |
get { return txtSocksPort.Text; } | |
} | |
public string LocalPort | |
{ | |
get { return txtLocalPort.Text; } | |
} | |
public string LogLine | |
{ | |
set { txtOutput.AppendText(value + Environment.NewLine); } | |
} | |
public static frmMain _formHandle; | |
public frmMain() | |
{ | |
InitializeComponent(); | |
notifyln("UI Initialized."); | |
_formHandle = this; | |
notifyln("Ready to bind a SOCKS IP:PORT to 127.0.0.1:PORT"); | |
} | |
public void notifyln(string input) | |
{ | |
txtOutput.AppendText(input + Environment.NewLine); | |
} | |
// some basic byte/string conversion tricks | |
static byte[] GetBytes(string str) | |
{ | |
byte[] bytes = new byte[str.Length * sizeof(char)]; | |
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); | |
return bytes; | |
} | |
static string GetString(byte[] bytes) | |
{ | |
char[] chars = new char[bytes.Length / sizeof(char)]; | |
System.Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length); | |
return new string(chars); | |
} | |
private void btnBind_Click(object sender, EventArgs e) | |
{ | |
if ( txtSocksIP.Text.Equals("") | txtSocksPort.Text.Equals("") | txtLocalPort.Text.Equals("") ) | |
{ | |
notifyln("You've entered incorrect values. Please try again."); | |
} | |
else | |
{ | |
// ServerAction(txtSocksIP.Text, Convert.ToInt32(txtSocksPort.Text), Convert.ToInt32(txtLocalPort.Text)); | |
TSocket ThisSocket = new TSocket(_formHandle); | |
ThisSocket.CreateListener(1234); | |
} | |
} | |
private void txtOutput_TextChanged(object sender, EventArgs e) | |
{ | |
// scroll to bottom | |
txtOutput.SelectionStart = txtOutput.TextLength; | |
txtOutput.ScrollToCaret(); | |
txtOutput.Refresh(); | |
} | |
private void frmMain_Load(object sender, EventArgs e) | |
{ | |
} | |
} | |
public class TSocket | |
{ | |
// using the class constructor to interface with the form fields | |
// create an instance of the form? how does this work? | |
private readonly frmMain form; | |
public TSocket(frmMain form) | |
{ | |
this.form = form; | |
} | |
public void CreateListener(int ListenerPort) | |
{ | |
form.Show(); | |
IPAddress LOCALHOST = IPAddress.Parse("127.0.0.1"); | |
form.LogLine = "test"; | |
TcpListener LocalListener = new TcpListener(LOCALHOST, ListenerPort); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment