Search code examples
c#.nettcpclient

How can I spoof an IP address to prevent being locked out from a service?


I need to do a whois towards a whois lookup. The website i've created cannot do all the requests, since it might be blocked.

So, I need to send the visitors ip-adress in the lookup. This is the code i have at the moment:

var name = "testadress.no";
var userIp = Request.ServerVariables["REMOTE_HOST"];
const string whoisServerAddress = "whois.host.no";
var strDomain = "-c utf-8 "+ name + "\r\n";
var bytDomain = Encoding.UTF8.GetBytes(strDomain.ToCharArray());

var tcp = new TcpClient();
tcp.Connect(whoisServerAddress, 43);
var s = tcp.GetStream();
s.Write(bytDomain, 0, strDomain.Length);

var sr = new StreamReader(tcp.GetStream(), Encoding.UTF8);
var strLine = "";
var result = new List<string>();
while (null != (strLine = sr.ReadLine()))
{
    result.Add(strLine);
}
tcp.Close();
return result;

Solution

  • The website i've created cannot do all the requests, since it might be blocked.

    You're abusing a third-party service. They most likely have terms of service to which you agreed by using the service, and they put rate limiting in place to enforce them.

    You need to contact them to discuss the possibilities to properly use their service.

    So, I need to send the visitors ip-adress in the lookup.

    You cannot spoof your sender IP to be that of your website visitor: even if you do so, the response will not be sent back to your server.

    @LIUFA Do this mechanism in Javascript.

    Since this is not a protocol implemented by browsers like WebSockets, and JavaScript doesn't let you open arbitrary socket connections, you also cannot do this from JavaScript.