Domain checker (Whois)? - c#

to all.
i developing a webpage using asp.net with c# language, in this webpage i have a textbox for taking url of the domain and button. when user enter domain name in the textbox and press the button the details of the domain will displaying in the other window. i take help from stackoverflow user and i get the code it is working fine, but when i type the domain name particularly ".in" doamins are not giving details. simply domain available message is displaying actually the domain is registered for example i tried "axisbank.co.in" in my page it is displaying the domain is available but actually it is already taken. I am sending my code please help me ( particularly .in domain names)
protected void Button1_Click(object sender, EventArgs e)
{
lblDomainName.Text = Session["WhoIs"].ToString();
string firstLevelbufData = null;
// Stores the bufData extracted from the webclient
try
{
// similarly we can select any server address for bufData mining
string strURL = "http://www.directnic.com/whois/index.php?query=" + txtDomain.Text;
WebClient web = new WebClient();
// byte array to store the extracted bufData by webclient
byte[] bufData = null;
bufData = web.DownloadData(strURL);
// got the bufData now convert it into string form
firstLevelbufData = Encoding.Default.GetString(bufData);
}
catch (System.Net.WebException ex)
{
// this exception will be fired when the host name is not resolved or any other connection problem
//txtResult.Text = ex.Message.ToString();//sasi
lblresult.Text = ex.Message.ToString();
return;
}
try
{
// first and last are the regular expression string for extraction bufData witnin two tags
// you can change according to your requirement
string first = null;
string last = null;
// chr(34) is used for (") symbol
first = "<p class=\"text12\">";
last = "</p>";
Regex RE = new Regex(first + "(?<MYDATA>.*?(?=" + last + "))", RegexOptions.IgnoreCase | RegexOptions.Singleline);
// try to extract the bufData within the first and last tag
Match m = RE.Match(firstLevelbufData);
// got the result
//txtResult.Text = m.Groups["MYDATA"].Value + "<br>";//sasi
lblresult.Text = m.Groups["MYDATA"].Value + "<br>";
// check if no information abour that domain is available
//if (txtResult.Text.Length < 10) txtResult.Text = "Domain "+ txtDomain .Text +" is Available";//sasi
if (lblresult.Text.Length < 10)
lblresult.Text = "Domain " + txtDomain.Text + " is Available";
}
catch (System.Net.WebException ex)
{
lblresult.Text = " Sorry the information is currently not available !! ";
}
}
help me thank you

http://www.directnic.com
does not have information about .co.in domain names.
Most of the whois sites won't allow you to fetch the results before filling in CAPTCHA.
http://registry.in/ is the official registry, try using whois protocol at whois.registry.in

Related

How do i make an else or if statement creating text into usrNameLabel when it does not find the website url i specified at the top

So i want to display [NOT FOUND] if the web request doesnt find the url specified with strings above.
What I have done is a HWID system to identify the current user. it combines 2 strings to find my github repository and in that repository a file titled with their hwid and it displays their user name inside.
I want to make it so that if it does not find that file/website url/git repository that it displays Not Found.
Everything was defined before hand / everything works how it should but if it does not find the
url it will just crash.
or if it gets removed.
also this will happen if it does not find a connection to the internet.
but i have a fix for that which will switch the text to Not Connected when the check for Online/Offline status comes back as Offline.
i have read some on else statements and as far as i know it needs an if statement above.
i dont have one there because my code did not require one before.
Can someone please help me rewrite it?
code:
private void Form1_Load(object sender, EventArgs e)
{
HWID = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value;
textBox1.Text = HWID;
//downloads the username of the user
WebClient client = new WebClient();
string GithubRepository = "INSERT GITHUB LINK";
string GithubRepositoryImg = "INSERT OTHER GITHUB LINK";
string urlEndInPNG = ".png";
String strPageCode = client.DownloadString(GithubRepository+=HWID);
string strProfPicUrl = GithubRepositoryImg += HWID += urlEndInPNG;
usrNameLabel.Text = strPageCode;
// Insert else or if statement that says it to display "[NOT FOUND]" when it doesnt find it.
//my try
else{
usrNameLabel.Text = "Not Found";
}
What it displays when it finds the url
Image of what it displays
I have googled how to create one but it does not work pls help.
thank you
I think you need a try-catch more than an if/else statement.
Try as following:
private void Form1_Load(object sender, EventArgs e)
{
HWID = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value;
textBox1.Text = HWID;
//downloads the username of the user
WebClient client = new WebClient();
string GithubRepository = "INSERT GITHUB LINK";
string GithubRepositoryImg = "INSERT OTHER GITHUB LINK";
string urlEndInPNG = ".png";
string strPageCode = string.Empty;
try
{
strPageCode = client.DownloadString(GithubRepository += HWID);
}
catch (Exception ex)
{
usrNameLabel.Text = "Not Found";
}
string strProfPicUrl = GithubRepositoryImg += HWID += urlEndInPNG;
usrNameLabel.Text = string.IsNullOrEmpty(strPageCode) ? usrNameLabel.Text : strPageCode;
}
When the code throws the exception, label's text will be set to "Not Found", in case it doesn't find the repository you're searching for.

C# inserting a jpg file into an Outlook email message

This is my first time posting a question although I have been lurking and learning from all of you for a while now. I have been developing a C# Windows Form application that automates several day to day activities. One of the simplest pieces of this application is really giving me a hard time.
I need to insert two jpg files into an Email that I am responding to. I can accomplish this by pulling the files directly from the drive but would prefer them to be stored as a resource in the executable. This way I can pass the EXE to others and they can use it also. Here is an example of the code that works when it is stored locally. what I would prefer to do however is replace #"H:\ISOIR\PhishMeIcon.jpg" with Resource1.PhishMeIconJPG . I have seen several discussion about streams and converting the file to Byte format but this does not seem to interact well with Outlook.
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Make sure you have the Email reporting the incident Open");
string inc_num;
inc_num = incident_number.Text;
Microsoft.Office.Interop.Outlook.Application aPP = new Microsoft.Office.Interop.Outlook.Application(1);
Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)aPP.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.Folder f = aPP.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts) as Microsoft.Office.Interop.Outlook.Folder;
Microsoft.Office.Interop.Outlook.Inspector inSpect = null;
Microsoft.Office.Interop.Outlook.MailItem sMail = null;
Microsoft.Office.Interop.Outlook.MailItem rMail = null;
Microsoft.Office.Interop.Outlook.Attachment phishICO = null;
try
{
inSpect = aPP.ActiveInspector();
sMail = inSpect.CurrentItem as Microsoft.Office.Interop.Outlook.MailItem;
rMail = sMail.ReplyAll();
phishICO = rMail.Attachments.Add(#"H:\ISOIR\PhishMeIcon.jpg", Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, null, "name");
string imageCid = "PhishMeIcon.jpg#123";
phishICO.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid);
rMail.Subject = ("INC- ") + inc_num;
rMail.HTMLBody = Resource1.SPAM_Response_P1 + String.Format("<body><img src=\"cid:{0}\"></body>", imageCid) + Resource1.SPAM_Response_P2 + rMail.HTMLBody;
rMail.HTMLBody = rMail.HTMLBody.Replace("XXXX", inc_num);
rMail.Save();
MessageBox.Show("Your Email has been saved in your DRAFT Folder for review");
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message,
"An exception is occured in the code of add-in.");
}
finally
{
if (sMail != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(sMail);
if (rMail != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(rMail);
if (inSpect != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(inSpect);
}
}

OpenLdap C# bind with escaped characters in Distinguished Name

I have some working LDAP code in which we rebind to the found user in order to validate the user, using his distinguished name. Effectively this is what is happening:
string userDn = #"cn=Feat Studentl+umanroleid=302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB";
string fullPath = #"LDAP://surinam.testsite.ac.uk:636/" + userDn;
DirectoryEntry authUser = new DirectoryEntry(fullPath, userDn, "mypassword", AuthenticationTypes.None);
authUser.RefreshCache();
However this causes error unknown error 80005000 at DirectoryEntry.Bind()
I suspected the problem might be that the DN has a '+' and a '=' in the CN attribute. Therefore after finding that the way to escape this should be with a \ and the hex value of the character I tried this:
string userDn = #"cn=Feat Studentl\2Bumanroleid\3D302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB";
However I get the error:
Login failure: unknown user name or bad password
I assume this is because that now it is happy with the request but it is failing to match the users DN, for some reason.
Is there anyway around this?
In my experience developing LDAP services, whenever you get a login failure due to invalid credentials, that does tend to be the issue with the bind attempt. You're getting that error because DirectoryEntry does not parse the escaped characters in the DN... however, you shouldn't have to do that in the first place.
In your code - setting the AuthenticationTypes to "None" forces the entry to make a Simple bind based on the DN you're providing. Since your including the server name as part of the path, I would try using the ServerBind auth type instead, like this :
string LdapPath = ("LDAP://" + ldapUrl + "/" + Domain);
//Build the user and issue the Refresh bind
var dirEntry = new DirectoryEntry
{
Path = LdapPath,
Username = _usernameToVerify,
Password = _passwordToVerify,
AuthenticationType = AuthenticationTypes.ServerBind
};
//This will load any available properties for the user
dirEntry.RefreshCache();
Also, it looks like you're making this call to the secure LDAP port (636), so make sure you also include AuthenticationTypes.SecureSocketsLayer along with the ServerBind mechansim :
AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.SecureSocketsLayer
Hope this helps!
I had to resort to digging through an old DLL project that was customised for one customer.
I managed to get it to work. It appears you have to refer to these low level Directory Services routines if you have a DN with escape characters. (Note in real life the DN is obtained by an initial felxible user search by setting up a DirectorySearcher and doing FindOne first)
string userDn = #"cn=Feat Studentl+umanroleid=302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB";
string basicUrl = #"surinam.testsite.ac.uk:636";
var ldapConnection = new LdapConnection(basicUrl);
ldapConnection.AuthType = AuthType.Basic;
LdapSessionOptions options = ldapConnection.SessionOptions;
options.ProtocolVersion = 3;
options.SecureSocketLayer = true;
NetworkCredential credential = new NetworkCredential(userDn, password);
ldapConnection.Credential = credential;
try
{
ldapConnection.Bind();
Console.WriteLine("bind succeeded ");
}
catch (LdapException e)
{
if (e.ErrorCode == 49)
{
Console.WriteLine("bind failed ");
}
else
{
Console.WriteLine("unexpected result " + e.ErrorCode);
}
}
catch (DirectoryOperationException e)
{
Console.WriteLine("unexpected error " + e.Message);
}

Message with new line character is displayed as html code

I am using following code to post multiline message on facebook wall/page. but it is appear as shown in image (the text are different here). here is my code.
string path = "/me/feed";
string token = fbLoginDialog.FacebookOAuthResult.AccessToken;
dynamic messagePost = new ExpandoObject();
messagePost.message = #"Hello guys!
How are you?
Can you help me on this?";
var fb = new FacebookClient(token);
try { var postId = fb.Post(path, messagePost); }
catch (Exception ex) { MessageBox.Show(ex.Message); }
I am using Facebook.dll Version: 5.0.1.0
Did you try Environment.NewLine?:
messagePost.message = "Hello guys!" + Environment.NewLine +
"How are you?"+ Environment.NewLine +
"Can you help me on this?";
Environment.NewLine is a platform independent property that inserts new line char for the selected environment.
Or maybe you have a problem with your syntax and it should be:
messagePost.message = #"Hello guys!\r\n How are you?\r\n Can you help me on this?";
I got it working using Facebook.6.0.22
download latest from here https://github.com/facebook-csharp-sdk/facebook-winforms-sample

asp.net Button type link should open on new window

using c# .net4.0
I am aware the asp.net button with in the gridview of type link does a post to the same page when clicked, i need make several manipualtion on server side before actually redirecting user to an external site hence i can't use Hyperlinkfield. What i need now is the external site htm page should open up in sperate window. I tried the following which works but source site's fonts get bigger???
heres what i tried
Response.Write("<script>");
Response.Write("window.open('http://www.google.co.uk','_blank')");
Response.Write("</script>");
Response.End();
may be i need a refresh source site??
Thanks
# Curt Here is the code for Hyperlink i tired
on page load added new button on gridview
HyperLinkField LinksBoundField = new HyperLinkField();
string[] dataNavigateUrlFields = {"link"};
LinksBoundField.DataTextField = "link";
LinksBoundField.DataNavigateUrlFields = dataNavigateUrlFields;
LinksBoundField.DataNavigateUrlFormatString = "http://" + Helper.IP + "/" + Helper.SiteName + "/" + Helper.ThirdPartyAccess + "?dispage={0}&token=" + Session["Token"];
LinksBoundField.HeaderText = "Link";
LinksBoundField.Target = "_blank";
GridViewLinkedService.Columns.Add(LinksBoundField);
GridViewLinkedService.RowDataBound += new GridViewRowEventHandler(grdView_RowDataBound);
to append external values (refe and appid) to navigate url
protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e)
{
string strvalue = "";
string strvalue1 = "";
string strRef = "";
string strAppId = "";
foreach (GridViewRow row in GridViewLinkedService.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
//reference and appid
strAppId = row.Cells[0].Text;
strRef = row.Cells[1].Text;
HyperLink grdviewLink = (HyperLink)row.Cells[5].Controls[0];
strvalue = grdviewLink.NavigateUrl;
strvalue1 = Regex.Replace(strvalue, "(.*dispage\\=).*/(services.*)", "$1$2");
grdviewLink.NavigateUrl = "~/My Service/FillerPage.aspx?nurl=" + strvalue1 + "&AppID=" + strAppId.ToString() + "&Ref=" + strRef.ToString();
}
}
}
public partial class FillerPage : System.Web.UI.Page
{
private string refno = null;
private string appid = null;
private string nurl = null;
private string strvalue1 = "";
private string newtoken = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.GetValues("AppID") != null)
{
appid = Request.QueryString.GetValues("AppID")[0].ToString();
}
if (Request.QueryString.GetValues("Ref") != null)
{
refno = Request.QueryString.GetValues("Ref")[0].ToString();
}
if (Request.QueryString.GetValues("nurl") != null)
{
nurl = Request.QueryString.GetValues("nurl")[0].ToString();
}
while receiving the long url it gets messed up(same query multiple times and all jumbled up)?????
is there a better way to pass parameters ???
you need to register script not response.write
so the code for you is :
ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language=JavaScript>window.open('http://www.google.co.uk','_blank')</script>");
Read more : ClientScriptManager.RegisterStartupScript.
In a situation where I need to run server side code, before then opening a new page, I sometimes create a Generic Handler File and link to this with a HyperLink, passing variables as Query Strings. Therefore something like:
/MyGenericFile.ashx?id=123
In this file, I would have some scripting that needs to be carried out, followed by a Response.Redirect().
As long as the HyperLink is set to target="_blank", the user won't even know they've been to a generic file, which is then redirected. It will appear as they've opened a new link.
Therefore the process would be:
User clicks link to .ashx file
Link opens in new window
Necessary scripting is ran
Response.Redirect() is ran
User is taken to web page (www.google.com in your example)
I believe this same process is used by advert management systems to help track clicks.
You can register a script to run on page load with ClientScriptManager.RegisterStartupScript.

Categories

Resources