How do I do a dns lookup ?

  • Thread starter Thread starter peak
  • Start date Start date
peak said:
I need to obtain the ip from an email address, any ideas?

strip out the domain name from the email address:
(untested - watch for typos, syntax, etc - directly typing in here..)

' this should give you mydomain.com
Dim strEmail As String = "(e-mail address removed)"
Dim strDomain As String = _
strEmail.SubString(strEmail.IndexOf("@"c)+1, _
strEmail.Length - strEmail.IndexOf("@"c))

Then use the methods in System.Net.Dns class to retrieve the IP address:

For Each ip As System.Net.IPAddress _
In System.Net.Dns.GetHostByName(strDomain).AddressList
MessageBox.Show(ip.ToString)
Next ip

Note that a domain could have multiple IP addresses associated with it which
is why we need the loop.

hope that helps..
Imran.
 
Hi,
This seems to return the www server instead of the smtp server,
here is what I typed

Dim ip As System.Net.IPAddress
Dim strDomain = "tiscali.co.uk"
For Each ip In System.Net.Dns.GetHostByName(strDomain).AddressList
MsgBox(ip.ToString)
Next ip
End

I am expecting to get the ip of
smtp.tiscali.co.uk
and instead I am getting the ip of
www.tiscali.co.uk

Any ideas?
 
Peak
It is likely that tiscali.co.uk and www.tiscali.co.uk are aliases for
the same IP address. If you want the IP address for smtp.tiscali.co.uk, I
would suggest that that be what you submit as the strDomain.

Good Luck.
Ron L
 
This is not what I am looking for. Every smtp server knows
how to obtain the smtp address for *any* email address.
This is known I understand as dns email lookup or dns
mx record lookup. This is what I need.
I have done some research since I initially posted this
question, and it seems that someone wrote how to do this
in C#. Here is the link, maybe someone can show how
this would look like in VB:
http://www.csharphelp.com/archives/archive43.html?printable=yes


Tia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top