LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2012, 08:10 PM   #1
clapika
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Unhappy Bash Script for Scapy


i'm try to make bash script for scapy.Below is my script

#!/bin/sh
scapy
a=IP(dst="192.168.0.111")/TCP(dport=(1,1024),flags="S")


Output:
Welcome to Scapy(2.2.0-dev)
>>>

it doesn't execute second line script.Please help me
 
Old 01-17-2012, 09:08 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
I don't use scapy, but I think I know what the problem is...

Quote:
Code:
#!/bin/sh
scapy
a=IP(dst="192.168.0.111")/TCP(dport=(1,1024),flags="S")
Scripting doesn't work that way. When your shell script encounters the line with "scapy," the shell runs scapy just as if you typed the command at the terminal. You will get the same interactive command prompt as usual.

If you want to automate entering commands into scapy then you should probably look at expect.

Some links to give you an idea:
LinuxJournal: Automating Tasks with EXPECT
The Geek Stuff: 6 Expect Script Examples to Expect the Unexpected (With Hello World)
 
Old 01-17-2012, 10:11 PM   #3
clapika
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
New Code:

#!usr/bin/expect -f
spawn scapy
expect ">>> ";
send "a=IP(dst="192.168.0.111")/TCP(dport=(1,1024),flags="S")\r";

Output:
spawn: command not found

I ready install expect package.And still cant find "spawn: command not found" solution from google
 
Old 01-17-2012, 10:25 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
#1

Code:
#!usr/bin/expect -f
That statement is missing the leading slash for an absolute path. It should be:
Code:
#!/usr/bin/expect

#2
Code:
spawn scapy
I suggest you (a) put the executable to spawn in double quotes and (b) as shown in most of the examples, give an explicit path to scapy. For instance:
Code:
spawn "/usr/local/bin/scapy"

#3
Expect scripts do not need semicolons at the end of each line


#4
Code:
send "a=IP(dst="192.168.0.111")/TCP(dport=(1,1024),flags="S")\r";
You have a problem here. You are trying to use double quotes within the quotes used for the send command. You need to escape the internal double quotes. If you do not, expect may get confused as to what text should sent. For instance:
Code:
send "a=IP(dst=\"192.168.0.111\")/TCP(dport=(1,1024),flags=\"S\")\r"
EDIT:

#5
Your expect script will also need an 'interact' command or another 'expect "<something here>"' command after your send command. Without one of those, the expect script will terminate immediately after sending the string--which will probably cause the command you sent to have no effect.

Last edited by Dark_Helmet; 01-17-2012 at 10:29 PM.
 
Old 01-17-2012, 11:57 PM   #5
clapika
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
This is my new script:

#!/usr/bin/expect
spawn "/usr/local/bin/scapy";
expect ">>> ";
send "a=IP(dst=\"192.168.0.111\")/TCP(dport=(1,1024),flags=\"S\");\r";
interact

Output:

ftp.sh: line 2: spawn: command not found
couldn't read file ">>> ": no such file or directory
ftp.sh: line 4: send: command not found
ftp.sh: line 5: interact: command not found

It's seem like the /usr/bin/except doesnt have command spawn,sen,interact
 
Old 01-18-2012, 12:23 AM   #6
clapika
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
I solved already.I need to change the file to .exp not .sh
Thx ^.^
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
LXer: Linux Scapy Guards Your Servers (part 2) LXer Syndicated Linux News 0 12-02-2010 09:50 PM
LXer: Linux Protects Your Servers with Scapy (part 1) LXer Syndicated Linux News 0 11-18-2010 04:50 PM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
SCAPY doubt suchi Linux - Networking 0 01-24-2007 11:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration