Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Portforwading to ssh server and make http request

$
0
0
Hello all,
I wanna connect to ssh server and send a http request which isn't permitted by my ip. How I can do it? This is my code but the result is not correct about my ip after forwarding port.
Thank so much.

public static void Main()
    {
        string remoteHost = "173.246.25.188";
        ConnectionInfo connectionInfo = new PasswordConnectionInfo(remoteHost, 22, "username", "password");
        SshClient client;
        //ForwardedPortLocal port;
        string boundHost = "127.0.0.1";
        uint boundPort = 8011;
        uint remotePort = 22;
        using(client = new SshClient(connectionInfo)){
            client.Connect();
            Console.WriteLine(client.IsConnected);
            SshCommand command = client.RunCommand("ls -l");
            Console.WriteLine(command.Result);
            ForwardedPortLocal port = new ForwardedPortLocal(boundHost, boundPort, remoteHost, remotePort);
            client.AddForwardedPort(port);
            port.Start();
            sendRequest();
            Console.ReadKey();
        }
    }

    public static void sendRequest()
    {   
        string url = "http://cmyip.com/";
        WebResponse response = null;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "GET";
        request.ContentType = "application/json";
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0";
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request.Referer = "http://bestappsmobi.com/";
        request.KeepAlive = false;
        request.ContentLength = 0;           
        request.Timeout = 15000;

        response = request.GetResponse();
        Console.WriteLine("coucou: {0}", response.ContentLength);
        Stream stream = response.GetResponseStream();
        StreamReader reader = new StreamReader(stream, Encoding.UTF8);
        String responseString = reader.ReadToEnd();
        Console.WriteLine(responseString);
        Console.ReadKey();
    }

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>