---
title: "Programmatically Accessing Network Interfaces"
description: "Accessing network interfaces in Ruby, Python, Perl, and Node.js. Practical notes and code examples on Programmatically in JS."
url: "https://h3manth.com/scribe/programmatically-accessing-network-interfaces/"
canonical_url: "https://h3manth.com/scribe/programmatically-accessing-network-interfaces/"
markdown_url: "https://h3manth.com/scribe/blog/programmatically-accessing-network-interfaces.md"
publishDate: "2013-12-30T00:00:00.000Z"
author: "Hemanth HM"
category: "node"
tags: ["node","ruby","python","cli"]
word_count: 76
reading_time_minutes: 1
x_markdown_tokens: 248
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Programmatically Accessing Network Interfaces

> Accessing network interfaces in Ruby, Python, Perl, and Node.js. Practical notes and code examples on Programmatically in JS.

How to programmatically access network interfaces in different languages.

## Ruby 2.1

```ruby
require 'socket'
Socket.getifaddrs.each do |i|
  puts "#{i.name}: #{i.addr.ip_address}" if i.addr.ip?
end

## Python
python
import netifaces
for face in netifaces.interfaces():
    print netifaces.ifaddresses(face)

## Perl
perl
my %addresses = map {
    ($_ => [
        map { Net::Interface::inet_ntoa($_) }
        $_->address,
    ]);
} Net::Interface->interfaces;
print %addresses;

## Node.js
javascript
var os = require('os');
console.log(os.networkInterfaces());
```

Nothing beats `ip addr show` but these are handy for programming!
