MTU-Changing program - Settings.lisp


/ Published in: Lisp
Save to your folder(s)

Everything that has to do with the settings.ini file.


Copy this code and paste it in your HTML
  1. ;;;; Functions that is soley for settings, craeting reading or writhin
  2.  
  3.  
  4. (defun get_interface_list ()
  5. "Returns a 2D list of mtu value and interface.
  6. First element is the MTU-Value(Integer), rest of the list is the Interface(String)"
  7. (let ((output (ext:run-shell-command "netsh interface ipv4 show subinterfaces" :output :stream))
  8. (split nil)
  9. (lines '()))
  10. (loop for line = (read-line output nil 'eof)
  11. until (eq line 'eof) do
  12. (setf line (cl-utilities:SPLIT-SEQUENCE #\Space line :remove-empty-subseqs t))
  13. (when line
  14. (cond (split
  15. (let* ((mtu-value (parse-integer (car line)))
  16. (interface (cdr (cdr (cdr (cdr line))))))
  17. (if (listp interface)
  18. (setf line (cons mtu-value interface))
  19. (setf line (list mtu-value interface))))
  20. (setf lines (cons line lines)))
  21. ((equal (char (car line) 0) #\-)
  22. (setf split t))))
  23. )
  24. (reverse lines)))
  25.  
  26. (defun load_settings ()
  27. "Read the settings file if it exists"
  28. (with-open-file (stream "settings.ini" :if-does-not-exist nil)
  29. (if stream
  30. (loop for line = (read-line stream nil 'eof)
  31. until (eq line 'eof) do
  32. (setf line (cl-utilities:SPLIT-SEQUENCE #\Space line :remove-empty-subseqs t))
  33. (when line
  34. (cond ((equal (car line) "mtu")
  35. (setf *mtu* (parse-integer (car (cdr (cdr line))))))
  36. ((equal (car line) "mtub")
  37. (setf *mtub* (parse-integer (car (cdr (cdr line))))))
  38. ((equal (car line) "interface")
  39. (let ((temp (format nil "~{~a ~}" (cdr (cdr line)))))
  40. (setf *interface* (subseq temp 0 (- (length line) 1))))))))
  41. 'None)))
  42.  
  43.  
  44. (defun create_settings (interface)
  45. "Create settings"
  46. (setf *mtu* (car interface))
  47. (setf *mtub* (car interface))
  48. (let ((temp (format nil "~{~a ~}" (cdr interface))))
  49. (setf *interface* (subseq temp 0 (- (length temp) 1))))
  50. 'created
  51. ;; Write to settings.ini
  52. )

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.