Snippets

Tuomas Hietanen Get local IPv4-address of the computer

Created by Tuomas Hietanen
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()

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.