lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 11-12-28 08:50 AM, chuck@allthehowards.com wrote:

I am trying to read my webserver file with MAC and IP addresses.

The following code was offered by Luiz that really is great.

=============================

s=[[
[DHCP IP: (192.168.20.109)] to MAC address 00:16:B6:94:60:26,
Tuesday, Dec 13,2011 19:06:03 and I would like to extract the MAC address
and
[DoS attack: Smurf] attack packets in last 20 sec from ip
[178.151.111.21], Tuesday, Dec 13,2011 07:14:20 and I would like to
extract the IP address
and [LAN access from remote] from 82.228.252.76:14961 to
192.168.20.109:42765 Monday, Dec 12,2011 09:57:50 and I would like to
extract the first IP address
]]


for a in s:gmatch("DHCP.-to MAC address (.-),") do print("MAC",a) end
for a in s:gmatch("DoS.-from ip.%[(.-)%]") do print("IP1",a) end
for a in s:gmatch("LAN.-%] from (.-):.- to") do print("IP2",a) end

=============================

I admit, I am still studying it to figure out how it works - but

can someone offer recommendations on opening the single file to read all this data

and creating 3 output files to each contain MAC address, IP1 and IP2.

Sample file would be: (of course with many multiple lines of each type.

 

[DHCP IP: (192.168.20.109)] to MAC address 00:16:B6:94:60:26, Tuesday, Dec 13,2011 19:06:03

[DoS attack: Smurf] attack packets in last 20 sec from ip [178.151.111.21], Tuesday, Dec 13,2011 07:14:20

[LAN access from remote] from 82.228.252.76:14961 to 192.168.20.109:42765 Monday, Dec 12,2011 09:57:50



Hi Chuck
 
Maybe you could just edit the bit at the end that prints the three variables. You could just write a little function to write to a file and then call it three times with the three variables and three file names.

This is covered around page 196 of programming in Lua.

Hope this helps-Patrick