• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 716
  • 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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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