Python Forum
run scapy from python script ..
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
run scapy from python script ..
#11
(Sep-12-2018, 08:11 AM)buran Wrote: it's because your file name is scapy.py. You import your own file, not scapy package. Rename your file.

okay thank u its working now ... but i have another issue i need to get all the mac address from the arp_scan() function ... and pass them to another to get the vendor for each mac this is my code ... :
#! /usr/bin/python
import urllib2
import json
import codecs

def arp_scan():

        from scapy.all import srp,Ether,ARP,conf
        conf.verb=0
        ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.20.0/24"),timeout=2)
        for snd,rcv in ans:
                d = rcv.sprintf("%Ether.src%")
                print(d)
                
                
arp_scan()



#API base url,you can also use https if you need
url = "http://macvendors.co/api/"
#Mac address to lookup vendor from
mac_address =  arp_scan()

request = urllib2.Request(url+mac_address, headers={'User-Agent' : "API Browser"}) 
response = urllib2.urlopen( request )
#Fix: json object must be str, not 'bytes'
reader = codecs.getreader("utf-8")
obj = json.load(reader(response))

#Print company name
print (obj['result']['company']);
error :

Error:
Traceback (most recent call last): File "/tmp/ArpScanner/arp.py", line 26, in <module> request = urllib2.Request(url+mac_address, headers={'User-Agent' : "API Browser"}) TypeError: cannot concatenate 'str' and 'NoneType' objects
Reply
#12
Your arp_scan function does not have a return statement, so it returns None by default. So that's what mac_address gets set to, and that causes the error. You need to return the string version of whatever MAC address you're looking for from the arp_scan function.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#13
(Sep-12-2018, 04:54 PM)ichabod801 Wrote: Your arp_scan function does not have a return statement, so it returns None by default. So that's what mac_address gets set to, and that causes the error. You need to return the string version of whatever MAC address you're looking for from the arp_scan function.
how ?
Reply
#14
With a return statement:

def add_two(x):
    return x + 2
Output:
>>> y = add_two(3) >>> y 5
I'm not sure exactly what should be returned out of your function, but you would use the return statement to do it. If this is new to you, you should check out the functions tutorial (link in my signature below).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,272 Jun-29-2023, 11:57 AM
Last Post: gologica
  Permission issue when using scapy jao 3 9,849 Feb-05-2022, 06:14 PM
Last Post: snippsat
  error in scapy attribute 'haslayer' evilcode1 5 6,555 Mar-02-2021, 11:19 AM
Last Post: evilcode1
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,930 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,312 May-28-2020, 05:27 PM
Last Post: micseydel
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,637 May-11-2019, 08:12 PM
Last Post: keames
  Help Importing Protocol Library Into Scapy joedirgy 0 2,069 May-02-2019, 07:31 PM
Last Post: joedirgy
  How to run python script which has dependent python script in another folder? PrateekG 1 3,161 May-23-2018, 04:50 PM
Last Post: snippsat
  How to call one python script and use its output in another python script lravikumarvsp 3 32,433 May-16-2018, 02:08 AM
Last Post: lravikumarvsp
  save the output from scapy to txt file evilcode1 11 10,874 Oct-10-2017, 02:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020