Skip to content

Instantly share code, notes, and snippets.

@Thorium
Created April 13, 2016 14:57
Show Gist options
  • Save Thorium/17184252d0284b78b63ef65e692d670b to your computer and use it in GitHub Desktop.
Save Thorium/17184252d0284b78b63ef65e692d670b to your computer and use it in GitHub Desktop.
Get local IPv4-address of the computer
open System;
open System.Net;
open System.Net.NetworkInformation;
let GetLocalIpv4Address() =
let interfaces = NetworkInterface.GetAllNetworkInterfaces()
let unicastAddresses =
interfaces |> Seq.map (fun i -> i.GetIPProperties().UnicastAddresses) |> Seq.concat |> Seq.toList
let item =
unicastAddresses |> Seq.find (fun a -> a.IPv4Mask.ToString() <> "0.0.0.0" && a.IPv4Mask.ToString() <> "255.0.0.0")
//|> Seq.find (fun a -> a.PrefixLength = 16)
item.Address.ToString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment