#!/usr/bin/env ruby
#this is the capture file from tcpdump for printer (9100) traffic
filename = 'cap.pcl'
capdata = {}
File.open(filename,"r") {|capdata| capdata.read}
#this is the regex that identifies the print job type as PCL or PJL
if capdata.unpack("H*")[0] =~ /(1b45|1b25|1b26)/
printjobtype = "PCL"
print_good("Printjob of type PCL recieved")
#trying to extract only the data between these 2 markers
print_job_pcl = Array(pcdata.unpack("H*")[0].match(/((1b45|1b25|1b26).*(1b45|1b252d313233343558))/i)[0]).pack("H*")
end
## error I'm receiving,
## extractPrintJob.rb:8: undefined method `unpack' for #<File:cap.pcl (closed)> (NoMethodError)
Ruby: undefined method 'unpack' when I'm trying to extract data between to regex markers in a hex file
1.3k views Asked by user1635052 At
0
There are 0 answers
Related Questions in RUBY
- how to integrate cashfree payment gateway in ruby on rails project
- RSpec Capybara throwing Selenium error when trying to click a button with browser confirm
- Duplicate GET requests - Rails & Heroku
- convert csv file with json data inside to a column, rows table in 2nd csv file
- Installing dependencies from a gemspec file
- Verifying Google Identity OAuth2 token with Ruby
- Java code of AES/GCM/NoPadding encryption algorithm with authentication tag
- How to fix error in model with gem lockbox
- Cannot install Ruby Gem on Window
- use logstash filter ,aes gcm encrypted in ruby,but cannot decrypted in java
- In Rails 7, what is the right ActiveRecord callback to use if I need to prevent (or rollback) persistance on error?
- How can I go through an array and still remove elements from it
- Nokogiri only returning 5 results
- How do I get the fullscreen mode in firefox?
- undefined group option when using branch reset group regex in Ruby
Related Questions in METHODS
- Why does print(list.sort()) result in None?
- method doesn't fill the array with correct values - instead it leaves it at null
- How do I create a method in a class to delete the class instance?
- How can I ensure incremental changes in deciphered messages in Python substitution cipher decoding?
- Using a list of tuple and a relative item of a Tuple as an argument of a method
- How to create a list of a three sentence docstring with each element in the list being one sentence with its punctuation mark in Python?
- My search function is only matching exact strings
- How do I pass a generic function as an argument to another function in golang?
- In C#, How can an interface (such as ILogger), with 1 method signature for log(), show 5 on intellisense?
- What methods inherited from the Object class should usually be overridden?
- Method definition and objects in Java
- Argument list is changing whenever I execute a change to a separate list with removerange
- Why does my Javascript method return NaN when two number types are calculated?
- Method declaration being treated as a parameter
- How can the Toy object I get from a Child object not be the same as passed in through the constructor?
Related Questions in UNDEFINED
- onEdit() 'row is not defined' error using checkboxes
- Getter returns undefined in if statement. Seems not working for comparisons
- app.js:55 Uncaught TypeError: Cannot read properties of undefined (reading 'value')
- Leave Request Automation System
- "errors": [ { "detail": "Cannot read property '0' of undefined" how do I get to solve?
- An async function UserTest calls and awaits an async function GetUser but the value returned by GetUser is undefined
- I am trying a display items (events) from db typescript nestjs using handlebars the events are an array of object. Properties of each object undefined
- Is there a way to fix Undefined data in table cells?
- Can't call javascript function from a anchor element in innerhtml - undefined
- I found a strange behavior in JS. How to stop this behavior
- build error while instrumenting opentelemetry into c++ application
- Getting an undefined body in express PUT request
- Why am i getting error "Uncaught ReferenceError: increment is not defined"
- Country name array key not defined, how can I fix this?
- Ubuntu 22.04 libgtk-3.so: undefined reference to symbol 'gdk_window_hide'
Related Questions in UNPACK
- TypeError: cannot unpack non-iterable NoneType object. i want get df of twelvedata.timeseries.timeSeries object how can i do this i was abl todo it b4
- Python uses the unpack function of the strike module to decode double floating point numbers
- How to use the unpack function in the struct module in python
- Cant save modified files in archive
- How can I check that my Android app is not tampered with during runtime?
- After setting Xamarin forms IOS part of the project as startup option project I get The "UnpackFrameworks" task failed unexpectedly error
- Why does struct.unpack() not return a value that I expect?
- Processing Linux input events (/dev/input/event*) in PHP
- How to arch06 unpack
- Transform 4 level Dictionary to DataFrame
- Unpacking a dictionary
- Creating a list with a recursive function by unpacking multiple dimensional list into one dimensional list
- Unpacking of tuples of varying sizes in Julia
- How to unpack msgPack messages?
- Complete beginner! Error while running this code that I am unable to identify and fix
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)