• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

c#, winform app, how do I retrieve the users (internet) ip address?

c#, winform app, how do I retrieve the users (internet) ip address?
0
amillyard
Asked:
amillyard
  • 6
  • 4
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
In VB.Net, I have this code:
Dim strHostName As String
 
strHostName = System.Net.Dns.GetHostName()
Return System.Net.Dns.GetHostEntry(strHostName).AddressList(0).ToString

Open in new window

0
 
amillyardAuthor Commented:
well, I have got as far as this, but not working yet:  (c# version)

string strHostName = System.Net.Dns.GetHostName();
string strIPAddress = System.Net.Dns.GetHostEntry(strHostName).AddressList(0).ToString;
0
 
Éric MoreauSenior .Net ConsultantCommented:
you have 2 errors:
string strHostName = System.Net.Dns.GetHostName();
string strIPAddress = System.Net.Dns.GetHostEntry(strHostName).AddressList[0].ToString();

Open in new window

0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
amillyardAuthor Commented:
I see.  This appears to work, but I am not getting the normal ip address format xxx.xxx.xxx.xxx

my ip address came back as:   fe80::180b:31f2:

how do I convert this?
0
 
Éric MoreauSenior .Net ConsultantCommented:
I don't know. I am getting a normal IP address.
0
 
amillyardAuthor Commented:
mmm... I see -- is it a Vista issue? -- newer ip address protocol standard or something?
0
 
Éric MoreauSenior .Net ConsultantCommented:
maybe, I have XP at work (and no Vista under hands to try it)
0
 
Éric MoreauSenior .Net ConsultantCommented:
from http://bytes.com/forum/thread493790.html, can you try

Public Function Get_LocalIPAddress() As String

Dim h As System.Net.IPHostEntry =
System.Net.Dns.GetHostEntry(System.Net.Dns.GetHost Name)

'return any string found

Get_LocalIPAddress = CType(h.AddressList.GetValue(0), System.Net.IPAddress).ToString

End Function
0
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
amillyardAuthor Commented:
many thanks :-)
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now