http - Header Check C# is always 403? -



http - Header Check C# is always 403? -

im trying ping list of domains initial indications if exist - if dont exist dont ping - throws , exception. not problem, except reason redirects dont ping back.

so im trying http header responce of exception url. no matter 403 response. ideas?

private void hunt_click(object sender, eventargs e) { listbox1.items.clear(); string hostaddress = txtkeyword.text; string combined; string[] strarray = new string[] { ".com", ".net", ".org", ".ca", ".gov" }; foreach (string str in strarray) { combined = hostaddress + str; string result = string.empty; seek { ping ping = new ping(); int timeout = 1500; pingreply pingreply = ping.send(combined, timeout); if (pingreply != null && pingreply.status.tostring() != "timedout") { result = "address: " + pingreply.address + "\r" + "roundtrip time: " + pingreply.roundtriptime + "\r" + "ttl (time live): " + pingreply.options.ttl + "\r" + "buffer size: " + pingreply.buffer.length + "\r"; listbox1.items.add(combined + " " + result); } else { listbox1.items.add(combined + " not found"); } } grab (exception pingerror) { httpwebrequest request = (httpwebrequest)webrequest.create("http://www."+combined); request.method = "head"; httpwebresponse response = (httpwebresponse)request.getresponse(); httpstatuscode status = response.statuscode; listbox1.items.add(status); } } }

thanks in advance

edit ping error follows:

system.net.networkinformation.pingexception: exception occurred during ping request. ---> system.net.sockets.socketexception: no such host known @ system.net.dns.getaddrinfo(string name) @ system.net.dns.internalgethostbyname(string hostname, boolean includeipv6) @ system.net.dns.gethostaddresses(string hostnameoraddress) @ system.net.networkinformation.ping.send(string hostnameoraddress, int32 timeout, byte[] buffer, pingoptions options) --- end of inner exception stack trace --- @ system.net.networkinformation.ping.send(string hostnameoraddress, int32 timeout, byte[] buffer, pingoptions options) @ system.net.networkinformation.ping.send(string hostnameoraddress, int32 timeout) @ domainhunter.form1.hunt_click(object sender, eventargs e) in

your logic appears backwards (as read anyway). if ping throws exception if doesn't response sending head request server hopeless since server doesn't exist.

beyond ping not alternative you're trying accomplish. combination between dns.gethostaddresses (as suggested in comments) , seek open tcp connection port 80 and/or 443 (which ever appropriate sites you're trying check) tcpclient class determine if there server listening on ip discovered. there little else verify there server listening on ip you're trying check. doesn't check if url valid though maybe head after proving server there addition.

c# http header ping

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -