0

I am making a call to my python script via Java using jython . The python script has a scapy module (Python version : 2.7) . When I make a call using the below code ,I receive the below exception

    from scapy.all import *
  File "/Users/Library/Python/2.7/lib/python/site-packages/scapy/all.py", line 18, in <module>
    from scapy.arch import *
  File "/Users/Library/Python/2.7/lib/python/site-packages/scapy/arch/__init__.py", line 28, in <module>
    from scapy.arch.bpf.core import get_if_raw_addr
  File "/Users/Library/Python/2.7/lib/python/site-packages/scapy/arch/bpf/core.py", line 9, in <module>
    from ctypes import cdll, cast, pointer
ImportError: cannot import name cast

My Java code :

import org.python.core.*;

public class PythonCall {
    
public static void main(String[] args) {
    PythonInterpreter interp = new PythonInterpreter();
    interp.execfile("/Users/python_projects/PacketTrace/nettracer/DebugMonitor.py");
    
}
}

My python code :

import os
os.sys.path.append('/Users/Library/Python/2.7/lib/python/site-packages')
print os.sys.path
from scapy.all import *
from scapy.layers.http import HTTPRequest,HTTPResponse,HTTP 

class DebugMonitor(object):

def __init__(self):
        '''
        Constructor
        '''
        print "Debugging" 
        self.packetSniff()

def packetSniff(): 
      <Code to Sniff packets> 

if __name__ == '__main__':
    print os.sys.path
    os.sys.path.append('/Users/Library/Python/2.7/lib/python/site-packages')
    debug = DebugMonitor()

Has anyone faced this issue , any help is appreciated .

arpit joshi
  • 1,987
  • 8
  • 36
  • 62
  • That looks like a problem within scapy. Are you sure you have all the correct versions? – RufusVS Jul 26 '20 at 08:18
  • @RufusVS mac-os:~ arj$ pip install scapy DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: scapy in ./Library/Python/2.7/lib/python/site-packages (2.4.3) – arpit joshi Jul 26 '20 at 08:45
  • I don't think Jython is supported – Cukic0d Jul 26 '20 at 09:06
  • Means?Jython works fine , other normal python scripts are invoked correctly – arpit joshi Jul 26 '20 at 09:42
  • Can you just try creating and running the one line program (or run in an interpreter): `from ctypes import cast` because that's what seems to be the problem here. – RufusVS Jul 26 '20 at 16:46
  • I wrte one liner ```from ctypes import cast``` as standalone python program it runs fine , but with jython (ie:java calling python) it gives same error . – arpit joshi Jul 26 '20 at 20:23
  • 1
    Scapy does not work in Jython: https://github.com/secdev/scapy/issues/1962 – mzjn Jul 27 '20 at 11:25

0 Answers0