Net Scan
Requires nmap, grep & wget
include GtkEngine.e
include std/sequence.e
constant win = create(GtkWindow)
connect(win,"destroy",quit)
set(win,"default size", 300,300)
set(win,"title","Net Scan")
set(win,"border width",5)
set(win,"position",GTK_WIN_POS_CENTER)
constant panel = create(GtkVBox)
add(win,panel)
constant lbl1 = create(GtkLabel) set(lbl1,"alignment",0,0)
constant lbl2 = create(GtkLabel) set(lbl2,"alignment",0,0)
constant hl = create(GtkHSeparator)
pack(panel,{lbl1,hl,lbl2})
constant input = create(GtkEntry)
set(input,"tooltip text","Enter your lan address range here")
set(input,"text","192.168.2.1-32")
constant btnbox = create(GtkHButtonBox)
pack(panel,-btnbox)
function GetMyIP()
atom fn
object list = "<b>Computers on local network</b>\n"
object msg = "<b>This computer</b>\n"
-- get lan address;
if system_exec("ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' > myip ",0) = 0 then
fn = open("myip","r")
msg &= sprintf("My local network address: %s",{gets(fn)})
set(lbl1,"markup",msg)
close(fn)
show(lbl1)
else
Warn(0,"Error","Unable to get IP address!")
end if
-- get wan address;
if system_exec("wget -O - -q icanhazip.com > myip",2) = 0 then
fn = open("myip","r")
msg &= sprintf("My external IP: %s",{gets(fn)})
set(lbl1,"markup",msg)
show(lbl1)
close(fn)
else
Warn(0,"Sorry","No external IP")
end if
-- get other computers;
if system_exec(sprintf("nmap -sP -n %s | grep Host > iplist",{get(input,"text")}),2) = 0 then
fn = open("iplist","r")
while 1 do
msg = gets(fn)
if atom(msg) then exit
else
msg = split(msg)
list &= msg[2] & '\n'
end if
end while
close(fn)
set(lbl2,"markup",list)
else
Warn(0,"Sorry","Cannot find any computers","on this network")
end if
return 1
end function
constant get_my_ip = call_back(routine_id("GetMyIP"))
constant btn1 = create(GtkButton,"gtk-network")
set(btn1,"tooltip text","Click to scan network")
connect(btn1,"clicked",get_my_ip)
constant btn2 = create(GtkButton,"gtk-quit")
set(btn2,"tooltip text","Click to end this program")
connect(btn2,"clicked",quit)
add(btnbox,{input,btn1,btn2})
show_all(win)
main()
------------------------------------------------------------------------
-- Copyright 2010 by Irv Mullins all code released under the LGPL
------------------------------------------------------------------------