LoginSignup
7
8

More than 3 years have passed since last update.

ShinobiLayer: Hardware Firewallのアクセスログを取得するスクリプト

Last updated at Posted at 2015-01-28

はじめに

SoftLayerでは、Standard Hardware FirewallやDedicated Hardware Firewallなどを購入することで、ユーザーのPublic VLANにパケットが届く前に、不正なアクセスをブロックすることができます。以下のような操作でFirewallのアクセスログを確認することができるのですが、、、これを1つ1つのIPに対して手動で実施していくのは大変です。。。。
firewall1.jpg
firewall2.jpg

ということで、IPアドレスを指定すれば、それに紐づいているアクセスログを出力するサンプルスクリプトを作ってみましたのでご紹介したいと思います。

サンプルコード

getSyslogsByIP.py
import SoftLayer
import sys
import pprint
from prettytable import PrettyTable
pp = pprint.PrettyPrinter(indent=4)

argv=sys.argv
if ( len(argv) != 2 ):
    print("Usage: python %s <Your IP>." % argv[0])
    exit(10)

targetip = argv[1]
LIMITSIZE=500


client = SoftLayer.create_client_from_env()
myip = client['Network_Subnet_IpAddress'].getByIpAddress(targetip)
if (myip is None) or (myip == "") :
    print("You don't have  %s in your account." % (targetip))
    exit(20)

_offset=0
alllists=[]
while True:
    lists = client['Network_Subnet_IpAddress'].getSyslogEventsSevenDays(id=myip['id'], limit=LIMITSIZE, offset=_offset)
    alllists = alllists + lists
    _offset = _offset + LIMITSIZE
    if len(lists) < LIMITSIZE :
        break

if (alllists ==[]):
    print("No records for this IP")
    exit(0)

alllists = sorted(alllists, key= lambda x: x['createDate'], reverse=False)
table = PrettyTable(['createDate',
                     'sourceIpAddress',
                     'sourcePort',
                     'destinationIpAddress',
                     'destinationPort',
                     'protocol',
                     'eventType'])

for list in alllists:
    table.add_row([
                     list['createDate'],
                     list['sourceIpAddress'],
                     list['sourcePort'],
                     list['destinationIpAddress'],
                     list['destinationPort'],
                     list['protocol'],
                     list['eventType']
    ])

print(table)

使い方と出力結果

# python getSyslogsByIP.py <IP Address>
のように使ってください。このスクリプトだと、getSyslogEventsSevenDaysを使っているので、7日分のアクセスログが出力されます。もし1日分だけでよいのであれば、getSyslogEventsOneDayを使えば良いでしょう。
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet_IpAddress

getSyslogsResult.jpg

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8