nkat
Member
- Joined
- Jun 29, 2022
- Messages
- 21
- Programming Experience
- 1-3
Hello!
My goal is to scrape some data from a webpage 192.168.1.21/app/admin/directories.asp?id=username
The website that controls it needs login before querying directories. This is the problem I’m trying to solve. For that, I’ve read this post, and it addresses a lot of my questions, but does not solve the problem completely.
Important note, the 192.168.1.21 provides a user with 3 ways to login:
Then the post suggests a dev to replicate the request in his code. I took an example from the post and edited in the following way
but in both responses I got back the same login page. Just can not get through it.
Would someone please suggest a solution?
My goal is to scrape some data from a webpage 192.168.1.21/app/admin/directories.asp?id=username
The website that controls it needs login before querying directories. This is the problem I’m trying to solve. For that, I’ve read this post, and it addresses a lot of my questions, but does not solve the problem completely.
Important note, the 192.168.1.21 provides a user with 3 ways to login:
- a button “recognize me automatically” that runs JavaScript function loginNTLM()
- two fields, “username” and “password” that prompt a user to use his Active Directory credentials
- a field “superuser password” that requires just a password to login. The password is known to me
Then the post suggests a dev to replicate the request in his code. I took an example from the post and edited in the following way
login into a website:
using System.Net;
var cookieContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://192.168.1.21/app/admin");
request.CookieContainer = cookieContainer;
//set the user agent and accept header values, to simulate a real web browser
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
//SET AUTOMATIC DECOMPRESSION
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
Console.WriteLine("FIRST RESPONSE");
Console.WriteLine();
using (WebResponse response = request.GetResponse())
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
Console.WriteLine(sr.ReadToEnd());
}
}
request = (HttpWebRequest)HttpWebRequest.Create("http://192.168.1.21/app/admin/directories.asp?s=DEFAULT");
//set the cookie container object
request.CookieContainer = cookieContainer;
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
//set method POST and content type application/x-www-form-urlencoded
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//SET AUTOMATIC DECOMPRESSION
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
//insert your username and password
string data = string.Format("username={0}&password={1}", "root", "BadDog22");
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
request.ContentLength = bytes.Length;
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(bytes, 0, bytes.Length);
dataStream.Close();
}
Console.WriteLine("LOGIN RESPONSE");
Console.WriteLine();
using (WebResponse response = request.GetResponse())
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
Console.WriteLine(sr.ReadToEnd());
}
}
but in both responses I got back the same login page. Just can not get through it.
Would someone please suggest a solution?