Created
November 13, 2015 04:50
-
-
Save suzumura-ss/c75b25f14a68980b3cb2 to your computer and use it in GitHub Desktop.
Get IP myself in AWS Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import commands | |
class MyIP: | |
def rawips(self): | |
cmd = "awk 'NR!=1 { split($2,arr,\":\"); print arr[1] }' /proc/net/tcp|sort|uniq" | |
return commands.getoutput(cmd).split("\n") | |
def raw2str(self, raw): | |
n = [int(raw[n:n+2],16) for n in [6,4,2,0]] | |
s = map(str, n) | |
return '.'.join(s) | |
def ipaddrs(self): | |
return [self.raw2str(raw) for raw in self.rawips()] | |
def lambda_handler(event, context): | |
return MyIP().ipaddrs() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment