Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9068851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:17:32+00:00 2026-06-16T17:17:32+00:00

Using C# Winforms I am trying to automatically detect the local machines IP address

  • 0

Using C# Winforms I am trying to automatically detect the local machines IP address through which it can connect to a particular remote DNS/IP address.

One senario is running over a VPN, with the remote address being 10.8.0.1 and local address being 10.8.0.6, netmask of 255.255.255.252

Iterating through the local addresses and checking if the remote and local are on the same subnet obviously fails and I am unsure of how else to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:17:33+00:00Added an answer on June 16, 2026 at 5:17 pm

    Here is some sample code that should get you the information you’re looking for. It creates a UDP socket and calls Connect() on it (effectively a NOOP), and then checks the local address.

    static EndPoint GetLocalEndPointFor(IPAddress remote)
    {
        using (Socket s = new Socket(remote.AddressFamily,
                                     SocketType.Dgram,
                                     ProtocolType.IP))
        {
            // Just picked a random port, you could make this application
            // specific if you want, but I don't think it really matters
            s.Connect(new IPEndPoint(remote, 35353));
    
            return s.LocalEndPoint;
        }
    }
    
    static void Main(string[] args)
    {
        IPAddress remoteAddress = IPAddress.Parse("10.8.0.1");
        IPEndPoint localEndPoint = GetLocalEndPointFor(remoteAddress) as IPEndPoint;
    
        if (localEndPoint == null)
            Console.WriteLine("Couldn't find local address");
        else
            Console.WriteLine(localEndPoint.Address);
    
        Console.ReadKey();
    }
    

    Note that this is effectively an implementation of this answer, but in C#.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an auto-updating app using Winforms. I can't use click-once or
I am trying to make a multiple page application using winforms. I decied to
I’m using C# and Winforms. I’m trying to make a report that gives a
We are developing a multilingual Winforms application using visual studio 2008. I am trying
I'm trying to output unicode string into RTF format. (using c# and winforms) From
I am trying to send mail using SmtpClient() within my Winforms VB.Net program Here
Using winforms in vs2008. I have a DataGridView and I would like to detect
I am trying to do this using C#(Winforms). The code I am using is
I'm trying to access a windows service (also created by me) through a WinForms
Using the CoreScanner Driver provided by Motorola, I'm trying to write a small winforms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.