Display local IP address

From IronPython Cookbook

Showing the local IP address:

import clr
import socket
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox
 
address = socket.gethostbyname(socket.gethostname())
MessageBox.Show(address)

Alternatively:

import clr
from System.Net import Dns
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox

address = Dns.GetHostAddresses(Dns.GetHostName())
MessageBox.Show(address[0].ToString())

Originally by Domingo Aguilera. Return to Contents.

TOOLBOX
LANGUAGES