You can create simple window based apps using ironpython. By using ironpython you can quickly write python code to access .NET framework and respective methods. In this article you’ll learn how to get IP address of your local machine.
If you’re new to ironpython then consider reading introductory article on ironpython and respective tutorials. If you’re not newbie to ironpython then dive into code directly and check if it works for you.
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("IP Address: "+address[0].ToString())Line 1 : You’re importing CLR by calling : import clr
Line 2 : In this line you’re accessing DNS Class
Line 3 : As this program is window based, this line adds reference to : System.Windows.Forms
Line 4 : This line imports MessageBox class
Line 5 : We’re creating address variable that fetches IP address using : Dns.GetHostAddresses(Dns.GetHostName())
Line 6: This line calls for the message box that displays IP address
Hope this helps to those who are using ironpython in their network based apps. You can experiment more with other network classes from .NET framework. If you have any questions regarding this code or tutorial, feel free to comment.